我想在SlickGrid的某些列中添加自定义列属性。我有一个使用正则表达式验证输入的自定义编辑器。我想为我的列添加一个正则表达式语句属性,这样我就可以为每个列使用同一个编辑器,并从它们的列中获取唯一的正则表达式语句。 我希望列的格式如下:
var columns = [{ id: "id", name: "#", field: "id", cssClass: "cell-title", resizeable: true, sortable: true },
{ id: "upc", name: "UPC", field: "upc", resizable: true, sortable: true, editor: regexValidationEditor, regex: /^[a-zA-Z0-9 ]{0,20}$/ },
{ id: "price", name: "Price", field: "price", resizable: true, sortable: true, editor: regexValidationEditor, regex: /^\d*\.?\d{0,3}$/ }];
如果我能在我的验证函数中做出这样的操作:
function regexValidationEditor(args) {
var $value;
var inputBox = "<INPUT class='customInput' type=text />";
var scope = this;
this.init = function () {
$value = $(inputBox)
.appendTo(args.container);
scope.focus();
};
this.validate = function () {
if (!args.column.regex.test($value.val())) {
return { valid: false, msg: "Invalid Data Entry" };
}
return { valid: true, msg: null };
};
this.init();
}
显然,这不起作用,但这是我想要做的事情的基本思路。