我们可以通过更改免费jqgrid 4.15.4中的任何选定值来更新多个下拉值吗

时间:2018-08-25 17:54:27

标签: jqgrid free-jqgrid

我在我的一个应用程序中使用免费的jqgrid 4.15.4。我有一个问题,想一次更新多个列的下拉值。我正在使用multiselect:true,option。

我还了解了并发问题,但是现在这对我来说不是问题。

我添加了一个演示小提琴https://jsfiddle.net/tygLjmde/

$(function () {
"use strict";
var mydata = [
    { id: "10",  FirstName: "test", LastName: "TNT", Gender: "Male" },
     { id: "11",     FirstName: "test2",    LastName: "ADXC", Gender: "Male" },
     { id: "12",     FirstName: "test3",    LastName: "SDR", Gender: "Female" },
     { id: "13",     FirstName: "test4",    LastName: "234", Gender: "Male" },
     { id: "14",     FirstName: "test5",    LastName: "DAS", Gender: "Male" },
];
$("#list").jqGrid({
data: mydata,

    colNames: ['','Id', 'First Name', 'Last Name', 'Gender'],
     colModel: [
  {
            name: "act", template: "actions",
           formatoptions: {
               delbutton: false
         }
        },
        {
            label: "Id",
            name: 'Id',
            hidden: true,
            search: false,
        },
        {
            label: "FirstName",
            name: 'FirstName',
            searchoptions: {
                searchOperators: true,
                sopt: ['eq', 'ne', 'lt', 'le','ni', 'ew', 'en', 'cn', 'nc'],
            }, search: true,
        },
        {
            label: "LastName",
            name: 'LastName',
            searchoptions: {
                searchOperators: true,
                sopt: ['eq', 'ne', 'lt', 'ni', 'ew', 'en', 'cn', 'nc'],
            }, search: true,
        },

        {
            label: "Gender",
            name: 'Gender',
            search: true, 
            edittype: "select",editable: true,
            editoptions: {
            value: "Male:Male;Female:Female;" ,                                                                 
                        },
          stype: "select",
                editrules: {
                    custom: true,
                    custom_func: function (value, colName, iCol)                                                    {
                        alert("The value to validate: " +value);
                        return [true];
                    }
                    },
        },
        ],
        onSelectRow: function (id) {
        if (id && id !== lastsel) {
            jQuery('#list').restoreRow(lastsel);
            jQuery('#list').editRow(id, true);
            lastsel = id;
        }
    },
    loadComplete: function (id) {
        if ($('#list').getGridParam('records') === 0) {

            //$('#grid tbody').html("<div style='padding:6px;background:#D8D8D8;'>No records found</div>");
        }
        else {
            var lastsel = 0;
            if (id && id !== lastsel) {
                jQuery('#list').restoreRow(lastsel);
                jQuery('#list').editRow(id, true);
                lastsel = id;
              }
            }
        },

    pager: jQuery('#pager'),
    loadonce: true,
    viewrecords: true,
    gridview: true,
    width: 'auto',
    height: '450px',
        iconSet: "fontAwesome",
    multiselect: true,
    cellEdit:true,
    emptyrecords: "No records to display",
    jsonReader:
    {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        Id: "Id"
    },

});
$('#list').jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn", multipleSearch: true, searchOperators: true, search: true, loadFilterDefaults: true });
$('#list').jqGrid('navGrid', "#pager", {
    search: false, // show search button on the toolbar
    add: false,
    edit: false,
    del: false,
    refresh: true,
    reloadGridOptions: { fromServer: true }
});    
});

您将在第一列和“性别”列中看到复选框,其中包含带有值的下拉列表。因此,假设我选择了两行并仅更改了单行性别下拉列表值。 那么其他行性别列值是否有可能自动更改?如果是,那么任何演示/代码都会更改建议吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在演示中使用单元格编辑。因此,可以在更改值后使用afterSaveCell回调进行一些其他操作。您可以检查selarrrow参数的值,该参数包含选定行的ID列表,并可以使用setCell将行的“性别”列的值更改为新值:

afterSaveCell: function (rowid, cmName, value, iRow, iCol) {
    var $self = $(this);

    if (cmName === "Gender") {
        $self.jqGrid("getGridParam", "selarrrow").forEach(function (id) {
            var item = $self.jqGrid("getLocalRow", id);
            if (id !== rowid && item.Gender !== value) {
                $self.jqGrid("setCell", id, iCol, value, false, false, true);
            }
        });
    }
}

请参阅修改后的演示https://jsfiddle.net/OlegKi/20wh9a7g/