0

我需要在网格中为所有列添加排序选项(“事件键”、“日期”、“状态”、“事件编号”、“FF 死亡”、“OTH 死亡”、“财产损失”、“连续损失” ,'火灾原因') 分开。我试过了,但它不起作用,请在我的代码中修复排序问题,如果您对此有任何想法,请回答。

  showLoading();
        $("#list1").jqGrid({
            type: 'POST',
            url: 'include/LocationService.php?run=gridForCongressionalDistrict&address='+$('#address').val()+'&radius='+$('#radius').val()+'&query='+encodeURIComponent(query_condition),
            datatype: 'json',
            colNames:['Incident key','Date','State','Incident no','FF death', 'OTH death','Property Loss','Cont Loss','Fire Cause'],
            colModel :[ 
            {
                name:'a.INC_KEY', 
                index:'a.INC_KEY',
                width: 220,
               hidden: true,
                editrules: {
                   edithidden:true
               },
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            }, 

            {
                name:'a.INC_DATE', 
                index:'a.INC_DATE',
                width: 100,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            }, 

            {
                name:'a.INC_NO', 
                index:'a.INC_NO',
                width: 100,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }

            }, 

            {
                name:'a.STATE', 
                index:'a.STATE',
                width: 100,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            }, 

            {
                name:'a.FF_DEATH', 
                index:'a.FF_DEATH',
                width: 80,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            }, 

            {
                name:'a.OTH_DEATH', 
                index:'a.OTH_DEATH',
                width:80,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            },

            {
                name:'a.PROP_LOSS', 
                index:'a.PROP_LOSS',
                width: 80,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            },

            {
                name:'a.CONT_LOSS', 
                index:'a.CONT_LOSS',
                width: 80,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            },

            {
                name:'a.CAUSE_CODE_DESC', 
                index:'a.CAUSE_CODE_DESC',
                width: 240,
                searchoptions: {
                    sopt: ['eq', 'ne','cn']
                }
            },
            ],
            pager: '#pager',
            rowNum: 500,
            rowList:[500,100,20],
            sortname: 'INC_KEY',
            sortorder: 'desc',
            viewrecords: true,
            height: 400,
            width: 800, 
            shrinkToFit: false,
            gridview: true,
            caption: 'Reports',
            loadComplete: function(data){
                console.log('load complete'); 
                pin_data = data;
                viewReset = 'true';
                onSuccessFunction(data,'true');
            }
        });
        jQuery("#list1").jqGrid('navGrid','#pager',{
            edit:false,
            add:false,
            del:false
        });

        jQuery("#list1").jqGrid("clearGridData", true).setGridParam({
            url : 'include/LocationService.php?run=gridForCongressionalDistrict&address='+$('#address').val()+'&radius='+$('#radius').val()+'&query'+encodeURIComponent(query_condition),
            loadComplete: function(data){
                console.log('load complete');
                onSuccessFunction(data, 'true');  
            }
        }).trigger("reloadGrid")

        $("#error").html('<div class="error1"></div>');

    }
}  
)
})
4

2 回答 2

1

首先是您的主要问题的答案:您可以使用cmTemplate选项(有关详细信息,请参阅答案),该选项可用于更改colModel. 例如,

cmTemplate: { searchoptions: { sopt: ['eq', 'ne','cn'] } }

此外,我建议您将有关参数的信息从 URL 移动到postData. 所以

url: 'include/LocationService.php?run=gridForCongressionalDistrict&address=' +
        $('#address').val() + '&radius=' + $('#radius').val() +
        '&query=' + encodeURIComponent(query_condition),

url: 'include/LocationService.php',
postData: {
    run: 'gridForCongressionalDistrict',
    address: function () {
        return $('#address').val();
    },
    radius: function () {
        return $('#radius').val();
    },
    query: query_condition
}

在这种情况下,每个对服务器的请求都会重新计算值address,并且radius您将拥有当前$('#address').val()并将$('#radius').val()其发送到服务器。

于 2012-10-15T10:36:27.170 回答
0

{

searchoptions: { sopt: ['eq', 'ne','cn'] } }

url: 'include:yoursphp page.php?run=yoursfunctionsname&yoursaddingfunctions name=' +
        $('#yours varianle name').val() + sort=' + $('variable name').val() +
        '&query=' + encodeURIComponent(query_condition),

url name:"";

post data
{
}
return result():

或使用排序查询对事物进行排序并解析 jgrid 中的值。

于 2012-10-15T11:27:43.243 回答