ShieldUI Grid多个CustomEditors

时间:2018-03-26 16:08:42

标签: shieldui

我想知道是否有人在同一页面上使用过两个或更多个shieldui网格自定义编辑器。如何使用getCustomEditorValue函数(使用其库存示例更新)?我猜我需要在getCustomEditorValue函数中做一些事情来区分2个下拉列表?

$("#grid1").shieldGrid({
dataSource: {
data: products,
schema: {
    fields: {
        id: { path: "ProductID", type: Number},
        name: { path: "ProductName", type: String, nullable: false },
        quantity: { path: "SupplierID", type: Number },
        price: { path: "UnitPrice", type: Number },
        price2: { path: "UnitPrice2", type: Number },
        units: { path: "UnitsInStock", type: Number },
        discontinued: { path: "Discontinued", type: Boolean },
        myDate: { path: "d", type: Date }}}
      },
events: {
editorCreating: function(e) {
    if (e.field == "price") {
        e.options = { max: 50 };
    }
}
},
rowHover: false,
columns: [
{ field: "id" },
{ field: "name", width: "200px" },
{ field: "quantity" },
{ field: "price", editor: myCustomEditor },
{ field: "price2", editor: myCustomEditor2 },
{ field: "units" },
{ field: "discontinued" },
    { field: "myDate", format: "{0:MM/dd/yyyy}" }
],
events: {
    getCustomEditorValue: function (e) {
        e.value = $("#test").swidget().value();
        $("#test").swidget().destroy();
    }
},
editing: {
enabled: true,
event: "doubleclick
type: "cell"
}
});
function myCustomEditor(cell, item) {
$('<div id="test"/>')
    .appendTo(cell)
    .shieldDropDown({
        dataSource: {
            data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
        },
        value: !item["price"] ? null : item["price"].toString()
    }).swidget().focus();
}
function myCustomEditor2(cell, item) {
$('<div id="test2"/>')
    .appendTo(cell)
    .shieldDropDown({
        dataSource: {
            data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
        },
        value: !item["price2"] ? null : item["price2"].toString()
    }).swidget().focus();
}

1 个答案:

答案 0 :(得分:1)

感谢对答案的支持:

    getCustomEditorValue: function (e) {                        
                    if ($("#dropdown1").length > 0) {
                        e.value = $("#dropdown1").swidget().value();
                        $("#dropdown1").swidget().destroy();
                    }

                    if ($("#dropdown2").length > 0) {
                        e.value = $("#dropdown2").swidget().value();
                        $("#dropdown2").swidget().destroy();
                    }
                }