Jqgrid显示页1(0)为空

时间:2021-08-04 19:21:01

I have a question, when the grid is empty why does it show Page 1 of 0 can't it be Page 1 of 1 or something more reasonable?

我有一个问题,当网格为空时为什么它会显示第1页的0不能是1或更合理的?

Jqgrid显示页1(0)为空

My code

我的代码

var xml=client.responseText;
         var xmlDoc = $.parseXML(xml); 
         var $xml = $(xml);

         xml=xml.replace(/<productId>1/g, "<productId>"+productMap['1']);
         xml=xml.replace(/<productId>2/g, "<productId>"+productMap['2']);
         xml=xml.replace(/<productId>3/g, "<productId>"+productMap['3']);


            $('#configDiv').empty();
            $('#configDiv').html(  '<div id="configDetailsGrid" width="100%"><table id="list1" width="100%"></table><div id="gridpager"></div></div>');

            //var grid = jQuery("#list1");
            //var iconAlert;

            var getColumnIndexByName = function (grid, columnName) {
                var cm = grid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length;
                for (; i < l; i += 1) {
                    if (cm[i].name === columnName) {
                        return i; // return the index
                    }
                }
                return -1;
            },
            grid = jQuery("#list1"),
            iconAlert = '<span class="ui-state-error" style="border:0"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span></span>';
            grid.jqGrid({

              datastr : xml,
              datatype: 'xmlstring',
              //datatype: 'clientside',
              colNames:['cfgId','Name', 'Host','Operating System', 'Description','Product', 'Type', 'Last Updated Time','Last Updated By','',''],
              colModel:[
                  {name:'cfgId',index:'cfgId', width:90, align:"left", hidden:true},
                  //{name:'updateDate',index:'updateDate', width:12, align:'center', /*formatter: oldConfigurationWarning*/ },
                  {name:'cfgName',index:'cfgName', width:70, align:"left", formatter: 'showlink', formatoptions: {baseLinkUrl: '#'} },
                  {name:'hostname',index:'hostname', width:70, align:"left"},
                  {name:'osname',index:'osname', width:90, align:"left"},
                  {name:'cfgDesc',index:'cfgDesc', width:90, align:"left"},
                  {name:'productId',index:'productId', width:40, align:"left"},
                  {name:'cfgType',index:'cfgType', width:50, align:"left"},
                  {name:'updateDate',index:'updateDate',sorttype:'Date', width:120, align:"left"},
                  {name:'emailAddress',index:'emailAddress', width:120, align:"left"},
                  {name:'absolutePath',index:'absolutePath', width:90, align:"left", hidden:true},
                  {name:'fileName',index:'fileName', width:90, align:"left", hidden:true}
              ],
              pager : '#gridpager',
              rowNum:1000,
              rowList:[10,50,100],
              scrollOffset:0,
              height: 'auto',
              emptyrecords: 'No configurations loaded',
              autowidth:true,
              viewrecords: true,
              gridview: true,
              multiselect: true,
              xmlReader: {
                  root : "list",
                  row: "Response",
                  userdata: "userdata",
                  repeatitems: false
              },

              loadComplete: function () {
                    var count = grid.jqGrid('getGridParam');
                    var ts = grid[0];
                    if (ts.p.reccount === 0) {
                        grid.hide();
                        emptyMsgDiv.show();
                    } else {
                        grid.show();
                        emptyMsgDiv.hide();
                    }

                    //for showlink and icon alert having date difference more than 90 days
                    var iRow, row, trClasses, $cell,
                    icfgName = getColumnIndexByName(grid, 'cfgName'),
                    iupdateDate = getColumnIndexByName(grid, 'updateDate'),
                    mygrid = grid[0],
                    rows = mygrid.rows,
                    cRows = rows.length,
                    myLink = function (e) {
                        var $td = $(e.target).closest('td'),
                            text = $td.text(),
                            $tr = $td.closest('tr'),
                            rowid = $tr[0].id;
                            goToViewAllPage(rowid);
                    };
                for (iRow = 0; iRow < cRows; iRow += 1) {
                    row = rows[iRow]; // row.id is the rowid
                    trClasses = row.className.split(' ');
                    if ($.inArray('jqgrow', trClasses) > 0) {
                        // the row is a standard row (only if subGrid:true are used)
                        var cellvalue1,firstDate,secondDate;
                        $cell = $(row.cells[icfgName]);
                        cellvalue1=$(row.cells[iupdateDate]).text();
                        firstDate = new Date();
                        //console.info(cellvalue1+", "+cellvalue1.length);
                        //var cellvalue1="08-18-2011 11:49:01";
                        if(cellvalue1.length>25)
                        {
                            secondDate=new Date();
                            //secondDate = secondDate.substring(0, secondDate.length-3);

                            if(diffOf2Dates(firstDate,secondDate,true)>=expireCondition)
                            {
                                $cell.prepend(iconAlert);
                            }
                            $cell.click(myLink);
                        }
                        else
                        {

                            secondDate = cellvalue1.substring(0, cellvalue1.length-6);
                            if(diffOf2Dates(firstDate,secondDate,false)>=expireCondition)
                            {
                                $cell.prepend(iconAlert);
                            }
                            $cell.click(myLink);
                        }
                    }
                }

                },
              onSelectRow: function(id,status){

                  }
            });
            grid.jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false});

            var myGrid = $("#list1");
            $("#cb_"+myGrid[0].id).hide();

            // place div with empty message insde of bdiv
            emptyMsgDiv.insertAfter(grid.parent());

            //$("#list1").setGridParam({rowNum:10});
            //$("#list1").trigger("reloadGrid");

            $("#list1").setGridParam({rowNum:10}).trigger("reloadGrid");
            $("#list1").sortGrid('updateDate', false, 'desc');

My Xmldata (when empty)

我Xmldata(空的)

<Response>
<isSuccess>true</isSuccess>
<operation>viewall</operation>
<message>No configurations loaded</message>
</Response>

Update

更新

I updated accordingly but no still no luck, I still get the same old Page 1 of 0

我相应的更新了但还是没有运气,我还是得到了相同的老页面1的0

 xmlReader: {
                  /*root : "list",
                  row: "Response",*/
                  root:"Response",
                  row:"list",
                  userdata: "userdata",
                  repeatitems: false
              },

my jquery.jqGrid.min.js file changes

我的jquery.jqGrid.min。js文件的变化

if(locdata) {
            ts.p.records = gl;
            //Change after 1 of 0 (Oleg)ts.p.lastpage = Math.ceil(gl/ rn);
            ts.p.lastpage = Math.max(ts.p.page,Math.ceil(gl/ rn)); //line no 1181
}

my response

我的回答

<Response>
  <isSuccess>true</isSuccess>
  <operation>viewall</operation>
  <message>No configurations loaded</message>
</Response>

Update, something usefull

更新一些有用

If we reload the grid it solves the problem too

如果我们重新加载网格,这也解决了问题

jQuery("#list1").setGridParam({rowNum:10}).trigger("reloadGrid");

2 个解决方案

#1


3  

I don't see that the XML data corresponds to xmlReader which you use. Probably you should switch the values of root and row properties:

我不认为XML数据对应于您使用的xmlReader。可能您应该切换根属性和行属性的值:

xmlReader: {
    root : "list",
    row: "Response",
    userdata: "userdata",
    repeatitems: false
}

Additionally the input XML data contain no page, total and records properties. In case of usage of any other datatype as 'xml' or 'xmlstring' you can define page, total and records as functions inside of jsonReader. The xmlReader parameter don't support it.

此外,输入的XML数据不包含页、总数和记录属性。如果使用任何其他数据类型作为“xml”或“xmlstring”,您可以将页面、total和记录定义为jsonReader内部的函数。xmlReader参数不支持它。

Currently you don't define page, total and records properties. So the default values are used: page: "rows>page", total: "rows>total", records: "rows>records".

目前还没有定义页面、total和记录属性。因此使用默认值:page:“rows>page”,total:“rows>total”,records:“rows>records”。

The bug which I described in the answer and in the bug report is still not fixed in the code of jqGrid 4.2.0. So your current data will display "1 of NaN" before you apply the fix.

我在回答和bug报告中描述的bug仍然没有在jqGrid 4.2.0的代码中得到修正。因此,在应用修复之前,当前数据将显示“1 of NaN”。

After all you can consider to change the line 1193 of the jqGrid code

毕竟,您可以考虑更改jqGrid代码的第1193行

ts.p.lastpage = Math.ceil(gl/ rn);

to have other value in the lastpage.

在最后一页有其他值。

UPDATED: I suggest that you modify the line ts.p.lastpage = Math.ceil(gl/ rn); of the jqGrid code to ts.p.lastpage = Math.max(ts.p.page,Math.ceil(gl/ rn));.

更新:我建议你修改一下ts线。lastpage =数学。装天花板(gl / rn);jqGrid代码到ts.p。lastpage = Math.max(ts.p.page,数学。装天花板(gl / rn));。

In the case if your input data will contain no <page> element or if it contains <Response><page>1</page>... you will see 1 of 1. If your XML data will contain <Response><page>0</page>... you will see 0 of 0.

如果您的输入数据不包含 元素,或者它包含 1 …你会看到1 / 1。如果您的XML数据将包含 0 …你会看到0 (0)

#2


0  

I can't see any positive effect to Oleg's latest update and the use of max(), because in my use context, the code doesn't go through this part. However, there is another instance of ts.p.lastpage = ... in the source code.

我看不出Oleg的最新更新和max()的使用有什么积极的影响,因为在我的使用上下文中,代码没有经过这一部分。然而,还有另一个例子。lastpage =…在源代码中。

ts.p.lastpage = lp === undefined? 1 : lp;

ts.p。lastpage = lp === undefined?1:lp;

to be replaced with:

替换为:

ts.p.lastpage = lp === undefined || lp === 0 ? 1 : lp;

ts.p。=== ==未定义|| === 0 ?1:lp;

That worked for me.

为我工作。

#1


3  

I don't see that the XML data corresponds to xmlReader which you use. Probably you should switch the values of root and row properties:

我不认为XML数据对应于您使用的xmlReader。可能您应该切换根属性和行属性的值:

xmlReader: {
    root : "list",
    row: "Response",
    userdata: "userdata",
    repeatitems: false
}

Additionally the input XML data contain no page, total and records properties. In case of usage of any other datatype as 'xml' or 'xmlstring' you can define page, total and records as functions inside of jsonReader. The xmlReader parameter don't support it.

此外,输入的XML数据不包含页、总数和记录属性。如果使用任何其他数据类型作为“xml”或“xmlstring”,您可以将页面、total和记录定义为jsonReader内部的函数。xmlReader参数不支持它。

Currently you don't define page, total and records properties. So the default values are used: page: "rows>page", total: "rows>total", records: "rows>records".

目前还没有定义页面、total和记录属性。因此使用默认值:page:“rows>page”,total:“rows>total”,records:“rows>records”。

The bug which I described in the answer and in the bug report is still not fixed in the code of jqGrid 4.2.0. So your current data will display "1 of NaN" before you apply the fix.

我在回答和bug报告中描述的bug仍然没有在jqGrid 4.2.0的代码中得到修正。因此,在应用修复之前,当前数据将显示“1 of NaN”。

After all you can consider to change the line 1193 of the jqGrid code

毕竟,您可以考虑更改jqGrid代码的第1193行

ts.p.lastpage = Math.ceil(gl/ rn);

to have other value in the lastpage.

在最后一页有其他值。

UPDATED: I suggest that you modify the line ts.p.lastpage = Math.ceil(gl/ rn); of the jqGrid code to ts.p.lastpage = Math.max(ts.p.page,Math.ceil(gl/ rn));.

更新:我建议你修改一下ts线。lastpage =数学。装天花板(gl / rn);jqGrid代码到ts.p。lastpage = Math.max(ts.p.page,数学。装天花板(gl / rn));。

In the case if your input data will contain no <page> element or if it contains <Response><page>1</page>... you will see 1 of 1. If your XML data will contain <Response><page>0</page>... you will see 0 of 0.

如果您的输入数据不包含 元素,或者它包含 1 …你会看到1 / 1。如果您的XML数据将包含 0 …你会看到0 (0)

#2


0  

I can't see any positive effect to Oleg's latest update and the use of max(), because in my use context, the code doesn't go through this part. However, there is another instance of ts.p.lastpage = ... in the source code.

我看不出Oleg的最新更新和max()的使用有什么积极的影响,因为在我的使用上下文中,代码没有经过这一部分。然而,还有另一个例子。lastpage =…在源代码中。

ts.p.lastpage = lp === undefined? 1 : lp;

ts.p。lastpage = lp === undefined?1:lp;

to be replaced with:

替换为:

ts.p.lastpage = lp === undefined || lp === 0 ? 1 : lp;

ts.p。=== ==未定义|| === 0 ?1:lp;

That worked for me.

为我工作。