0

My jqGrid uses loadonce: true and has a pair of columns I'm trying to filter by. 'DeletedFlag' is a hidden column with a bit flag. The column 'Deleted?' is visible and displays either nothing (DeletedFlag == 0) or a timestamp (DeletedFlag == 1).

Is there a way to map the filter input from 'Deleted?' to 'DeletedFlag' as I have attempted in the code sample below? If not, is there a way to change the 'Deleted?' editoptions->value string to enable filtering by either an empty or non-empty string?

{ name: 'DeletedFlag', index: 'DeletedFlag', hidden: true, searchoptions: { sopt: ['eq'], searchhidden: true }},
{
   name: 'Deleted?', index: 'DeletedFlag', width: 70, sortable: false, editable: false,
   stype: 'select', /*edittype: 'checkbox',*/ searchoptions: { value: ':All;0:No;1:Yes' }
}

EDIT: posting the entire grid + test data

$(function () {
            var grid = $("#PSGrid");

            // get values from Products table
            var prodValues = $.ajax({
                url: "jqGridHandler.ashx?oper=pVals",
                async: false,
                success: function (data) {

                }
            }).responseText;

            // get values from Environments table
            var envValues = $.ajax({
                url: "jqGridHandler.ashx?oper=eVals",
                async: false,
                success: function (data) {

                }
            }).responseText;

            // get values from ServerTypes table
            var typeValues = $.ajax({
                url: "jqGridHandler.ashx?oper=tVals",
                async: false,
                success: function (data) {

                }
            }).responseText;

            var lastsel = -1;

            // build the grid
            grid.jqGrid({
                url: 'jqGridHandler.ashx',
                editurl: 'jqGridEditor.ashx',
                datatype: 'json',
                height: 550,
                width: 'auto',
                colNames: ['ID', 'Product', 'Environment', 'Hostname', 'IP', 'Description', 'Type', 'Ports Used', 'DeletedFlag', 'Deleted?'],
                colModel: [
                    { name: 'ID', index: 'ID', width: 50, sortable: true, hidden: true, editable: false, key: true, sorttype: 'int' },
                    {
                        name: 'Product', index: 'Product', width: 125, sortable: true, editable: true,
                        stype: 'select', searchoptions: { value: ':All;' + prodValues, sopt: ['eq'] },
                        formatter: 'select', edittype: 'select', editoptions: { value: prodValues },
                        editrules: { required: true }
                    },
                    {
                        name: 'Environment', index: 'Environment', width: 100, sortable: true, editable: true,
                        stype: 'select', searchoptions: { value: ':All;' + envValues, sopt: ['eq'] },
                        formatter: 'select', edittype: 'select', editoptions: { value: envValues },
                        editrules: { required: true }
                    },
                    {
                        name: 'Hostname', index: 'Hostname', width: 200, sortable: true, editable: true,
                        editrules: { required: true }
                    },
                    {
                        name: 'IP', index: 'IP', width: 125, sortable: false, editable: true
                    },
                    {
                        name: 'Description', index: 'Description', width: 200, sortable: true, editable: true,
                        editrules: { required: true }
                    },
                    {
                        name: 'Type', index: 'Type', width: 75, sortable: true, editable: true,
                        stype: 'select', searchoptions: { value: ':All;' + typeValues, sopt: ['eq'] },
                        formatter: 'select', edittype: 'select', editoptions: { value: typeValues },
                        editrules: { required: true }
                    },
                    { name: 'Ports Used', index: 'Ports Used', width: 80, sortable: false, editable: true },
                    { name: 'DeletedFlag', index: 'DeletedFlag', hidden: true, searchoptions: { sopt: ['eq'], searchhidden: true }},
                    {
                        name: 'Deleted?', index: 'Deleted?', width: 70, sortable: false, editable: false,
                        stype: 'select', /*edittype: 'checkbox',*/ searchoptions: { value: ':All;0:No;1:Yes' }
                    }
                ],
                rowNum: 10000, // show all rows hack (-1 is the proper way to do it but is bugged in this version of jqGrid)
                pager: '#PSGridPager',
                sortname: 'ID',
                pgbuttons: false,
                pgtext: null,
                viewrecords: false,
                sortorder: 'asc',
                ignoreCase: true,
                caption: 'Click a row to edit.  [Enter] to save, [Esc] to cancel.',
                loadonce: true,
                onSelectRow: function (id) {
                    if (id && id !== lastsel) {
                        grid.jqGrid('restoreRow', lastsel);
                        grid.jqGrid('editRow', id, true);
                        lastsel = id;
                    }
                },
                afterSubmit: function (response, postdata) {
                    $(this).jqGrid('setGridParam', { datatype: 'json' });
                    alert('hello');
                    return [true];
                }
            });

            grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn" });
            grid.jqGrid('navGrid', '#PSGridPager', { edit: false, add: true, del: true, search: false, refresh: true, paging: false },
                { /* edit options */ },
                { /* add options */
                    closeOnEscape: true,
                    closeAfterAdd: true,
                    reloadAfterSubmit: true,
                    width: 400
                },
                { /* delete options */
                    closeOnEscape: true,
                    reloadAfterSubmit: true
                });
            grid.jqGrid('navButtonAdd', '#PSGridPager', {
                caption: "Export to Excel",
                onClickButton: function () {
                    grid.jqGrid('excelExport', { url: "jqGridHandler.ashx" });
                }
            });
        });

Typical row (comma delimited):

'A4', 'Test/QA', 'BLDALTSGPOOFF04', '192.168.86.190', 'IIS 7 Web Farm', 'Web', '80', ''

4

1 回答 1

1

在我看来,您可以name: 'IsDeleted', index: 'DeletedFlag'在“IsDeleted”列中使用。我建议您重命名name: 'Ports Used', index: 'Ports Used'name: 'PortsUsed', index: 'PortsUsed'(不要在名称中使用空格)。

该演示似乎可以过滤您想要的数据。我在演示中使用了 JSON 数据

[
    ["10", "A4", "Test/QA", "BLDALTSGPOOFF04", "192.168.86.190",
     "IIS 7 Web Farm", "Web", "80", "0", ""],
    ["20", "A5", "Test/QA", "BLDALTSGPOOFF05", "192.168.86.178",
     "IIS 6 Web Farm", "Web", "8080", "1", "2013-06-26 17:02:02.843"]
]

作为网格的输入。

再推荐一个。在创建网格之前,您当前使用了3 个同步Ajax 调用 ( )。async: false我想您不能使用dataUrl,因为您使用formatter: 'select'并且想要显示其他数据,例如来自服务器的 JSON 响应。这样的行为是不好的。我建议您放置与来自jqGridHandler.ashx. 在beforeProcessing回调内部,您可以访问数据并可以使用setColProp方法更改or的value属性。如果您在回调中进行此类更改,那么您在jqGrid 处理 JSON 响应之前执行此操作。所以 jqGrid 将使用修改后的属性值。editoptionssearchoptionsbeforeProcessingvalue

于 2013-06-28T14:46:12.947 回答