SlickGrid 选择编辑器
我想为选择单元格创建一个动态填充的 html 选择。我从数据库中提取一些信息,每个行项目都不同。问题是编辑器丢失了初始数据,我不知道如何保留特定单元格的一些数据。以前有人这样做过吗?
function StandardSelectCellEditor($container, columnDef, value, dataContext) {
var $input;
var $select;
var defaultValue = value;
var scope = this;
this.init = function() {
$input = $("<INPUT type=hidden />");
$input.val(value);
}
$input.appendTo($container);
$select = $("<SELECT tabIndex='0' class='editor-yesno'>");
jQuery.each(value, function() {
$select.append("<OPTION value='" + this + "'>" + this + "</OPTION></SELECT>");
});
$select.append("</SELECT>");
$select.appendTo($container);
$select.focus();
};
this.destroy = function() {
//$input.remove();
$select.remove();
};
this.focus = function() {
$select.focus();
};
this.setValue = function(value) {
$select.val(value);
defaultValue = value;
};
this.getValue = function() {
return $select.val();
};
this.isValueChanged = function() {
return ($select.val() != defaultValue);
};
this.validate = function() {
return {
valid: true,
msg: null
};
};
this.init();
};
I want to make a dynamically populated html select for a select cell. I extract some information from a database which is different for every row item. The problem is that the editor loses the initial data and I don't know how to keep some data for a specific cell. Has someone done this before?
function StandardSelectCellEditor($container, columnDef, value, dataContext) {
var $input;
var $select;
var defaultValue = value;
var scope = this;
this.init = function() {
$input = $("<INPUT type=hidden />");
$input.val(value);
}
$input.appendTo($container);
$select = $("<SELECT tabIndex='0' class='editor-yesno'>");
jQuery.each(value, function() {
$select.append("<OPTION value='" + this + "'>" + this + "</OPTION></SELECT>");
});
$select.append("</SELECT>");
$select.appendTo($container);
$select.focus();
};
this.destroy = function() {
//$input.remove();
$select.remove();
};
this.focus = function() {
$select.focus();
};
this.setValue = function(value) {
$select.val(value);
defaultValue = value;
};
this.getValue = function() {
return $select.val();
};
this.isValueChanged = function() {
return ($select.val() != defaultValue);
};
this.validate = function() {
return {
valid: true,
msg: null
};
};
this.init();
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此处提出了类似的问题(但这不是光滑网格标记)。
我确实制作了一个 SelectEditor,具有灵活的选项范围,具体取决于我们所在的列。这里考虑的原因是您在列中编辑的值的数据类型将决定该字段的有效选择。
为此,您可以向列定义添加一个额外的选项(例如称为选项),如下所示:
]
并在您自己的 SelectEditor 对象的 init 方法中使用 args.column.options 访问该选项,例如这:
A similar queations was asked here (this one is however not slickgrid tagged).
I did make a SelectEditor, with a flexible range of options depending on the column we are in. The reason of thinking here is that the datatype of the value you edit in a column will determine the valid choices for this field.
In order to do this you can add an extra option to your column definitions (e.g. called options) like this:
]
and access that using args.column.options in the init method of your own SelectEditor object like this:
您可以稍微修改上面的 SelectCellEditor 来为每个单元格创建不同的选择选项。
现在可以轻松创建动态下拉编辑器。
You can slightly modify the above SelectCellEditor to create different select options for each cell.
Now it is easy to create a dynamic dropdown editor.
替换
为
如果它不适合您,则
replace
with
if it is not working for you
请尝试下面的代码。
在 slick.editors.js 中,定义一个新的编辑器。
然后,修改您的网格选项
};
并在列初始化时使用编辑器。
Please try the below code.
In slick.editors.js,Define a new editor.
Then, modify your grid options
};
And use the editor while columns initialization.
我还不能添加评论,但我需要在 HeiN 的答案中添加一些内容。
HeiN 的答案效果很好,但我收到的数据与我的选择选项不匹配,我仍然需要显示该数据......所以我必须修改选项中的 dataItemColumnValueExtractor 。如果列表中没有匹配的选项,这允许显示我的原始数据。
希望这对以后的人有所帮助。
I can't add comments yet, but I need to add something to HeiN's answer.
HeiN's answer works great, but I have data coming in that does not match my select options and I need to still display that data... so I have had to modify dataItemColumnValueExtractor in the options. This allows my original data to display if I do not have an option in the list to match.
Hope this helps somebody later down the line.