gpt4 book ai didi

javascript - Jqgrid 显示第 1 页,共 0 页为空

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:06:04 26 4
gpt4 key购买 nike

我有一个问题,当网格为空时,为什么它显示 Page 1 of 0 不能是 Page 1 of 1 或更合理的东西吗?

enter image description here

我的代码

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');

我的 Xmldata(为空时)

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

更新

我相应地进行了更新,但仍然没有运气,我仍然得到相同的旧Page 1 of 0

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

我的 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
}

我的回应

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

更新,有用的东西

如果我们重新加载网格它也能解决问题

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

最佳答案

我没有看到 XML 数据对应于 xmlReader你用的。也许你应该切换 root 的值和 row属性:

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

此外,输入的 XML 数据不包含 page , totalrecords特性。如果使用任何其他 datatype作为'xml''xmlstring'你可以定义 page , totalrecords作为 jsonReader 内部的函数. xmlReader参数不支持。

目前您没有定义page , totalrecords特性。所以使用默认值:page: "rows>page" , total: "rows>total" , records: "rows>records" .

我在 the answer 中描述的错误在the bug report在 jqGrid 4.2.0 的代码中仍然没有修复。因此,在应用修复之前,您当前的数据将显示“1 of NaN”。

毕竟你可以考虑换行1193 jqGrid代码的

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

lastpage 中有其他值(value).

已更新:我建议您修改 ts.p.lastpage = Math.ceil(gl/ rn); 行jqGrid 代码的 ts.p.lastpage = Math.max(ts.p.page,Math.ceil(gl/ rn)); .

如果您的输入数据不包含 <page>元素或者它是否包含 <Response><page>1</page>...你会看到1 of 1 .如果您的 XML 数据将包含 <Response><page>0</page>...你会看到0 of 0 .

关于javascript - Jqgrid 显示第 1 页,共 0 页为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7875953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com