gpt4 book ai didi

javascript - 我可以设置总页数并在单击下一页时使用 jq 网格中的 ajax 加载下一组记录吗?

转载 作者:行者123 更新时间:2023-12-03 07:54:56 32 4
gpt4 key购买 nike

我有一个动态 Jqgrid,我将数据填充为本地数据。此本地数据是使用 ajax 获取的,并且我从 ajax 调用获得的响应格式不正确,因此我编写了一个扩展函数,它为我提供了一个包含列名称、列模型和列数据的对象结果。这处理起来非常棒,并且成功地做到了这一点,但是当问题出现在分页上填充数据时,我被 Gunicorn 了并挂断了。

我调查了onPaging 函数并找到了加载网格的东西,但这并不能完全满足我的要求。

我需要实现的案例如下。

1) 在分页时通过 ajax 调用加载 JqGrid。
2) 假设我有 25 条记录,并且我需要在 Jqgrid 中一次加载和填充 5 条记录。但是,应该向用户显示 jqgrid 顶部的信息,表明显示 1 of 5 条记录1 of 5 page。现在,当用户单击下一页时,我需要制作 ajax 并填充接下来的 5 条记录,类似地,用户在顶部通知说 5 到 10 条记录5 页中的 2 条<显示/strong>。

下面是从提要绑定(bind)我的网格的函数。

function BindFeedsToGrid(data, visibleCol, loadXmlTable, pager, errorMessage) {
try {
var result = ConvertXmlToJson(data, visibleCol);
if (result) {
$("#" + errorMessage).text("");
$("#" + loadXmlTable).jqGrid({
datatype: 'jsonstring',
datastr: result.colData,
colNames: result.ColNames,
colModel: result.ColModel,
pager: $("#" + pager),
rowNum: 5,
rowList: [5, 10, 25, 50],
viewrecords: true,
width: "100%",
height: 'auto',
toppager: true,
recordpos: 'left',
recordtext: 'Display {0} of {1}',
pagerpos: 'right',
pgtext: 'Page {0} of {1}',
total:5,
//BS Page start
onPaging: function (pgButton) {
//debugger;
var currentPage = $("#" + loadXmlTable).getGridParam('page'); //get current page
var lastPage = $("#" + loadXmlTable).getGridParam("lastpage"); //get last page

var dropDownVal = $("#" + loadXmlTable).closest('.ui-jqgrid').find('.ui-pg-selbox').val();

if (currentPage - 1 == lastPage - 1)
$("#" + loadXmlTable).setGridParam({ page: lastPage }).trigger("reloadGrid"); // set the requested page to the last page value – then reload

var currentRecordCount = $("#" + loadXmlTable).getGridParam("reccount"); //get the record count
var recordsPerPage = $("#" + loadXmlTable).getGridParam("rowNum"); // get the records per page

var newValue = 0; // new value
if (pgButton === "user") {
newValue = $(".ui-pg-input").val();
}
else {

if (pgButton.indexOf("next") >= 0)
newValue = ++currentPage;
else if (pgButton.indexOf("prev") >= 0)
newValue = --currentPage;
else if (pgButton.indexOf("last") >= 0)
newValue = $("#" + loadXmlTable).getGridParam('lastpage');
else if (pgButton.indexOf("first") >= 0)
newValue = 1;
}

page = newValue > 0 ? newValue : currentPage;
pageSize = dropDownVal;

var tempres = setNextSetOfData();
$("#" + loadXmlTable).jqGrid("setGridParam",{ datastr: tempres.colData ,colNames:tempres.colNames,colModel:tempres.colModel }).trigger("reloadGrid");
},
//BS page end

gridComplete: function () {
var recs = parseInt($("#" + loadXmlTable.id).getGridParam("records"), 10);
if (isNaN(recs) || recs == 0) {
$("#gridWrapper").hide();
}
else {
$('#gridWrapper').show();
}
}
});
//$("#" + loadXmlTable).jqGrid('navGrid', '#' + pager, { add: false, edit: false, del: false, search: false, refresh: false },
// {}, {}, {}, { multipleSearch: true, multipleGroup: true, showQuery: true });

}
else {
$("#" + errorMessage).text("There is no available item/items to display in this list");
}
} catch (e) {
$("#" + errorMessage).text("Server did not Respond. Please check Domain/Server url in the edit part.").css({ "color": "red", "font-weight": "bold" });
}


}

更新1:我正在使用下面给出的示例 xml 构建 Json 对象

    <properties xmlns="http://example.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<property>
<name>Accessed</name>
<value>14.01.2016 12:20:08</value>
</property>
<property>
<name>Case no.</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>16/00017</value>
</property>
<property>
<name>Title</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>San Case 16</value>
</property>
<property>
<name>Type</name>
<value>Case</value>
</property>
<property>
<name>Responsible person</name>
<value>Administrator</value>
</property>
<property>
<name>Responsible unit</name>
<value>Products</value>
</property>
<property>
<name>Status</name>
<value>In progress</value>
</property>
</properties>
<properties xmlns="http://example.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<property>
<name>Accessed</name>
<value>14.01.2016 12:20:08</value>
</property>
<property>
<name>Case no.</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>16/00017</value>
</property>
<property>
<name>Title</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>San Case 16</value>
</property>
<property>
<name>Type</name>
<value>Case</value>
</property>
<property>
<name>Responsible person</name>
<value>Administrator</value>
</property>
<property>
<name>Responsible unit</name>
<value>Products</value>
</property>
<property>
<name>Status</name>
<value>In progress</value>
</property>
</properties>
<properties xmlns="http://example.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<property>
<name>Accessed</name>
<value>14.01.2016 12:20:08</value>
</property>
<property>
<name>Case no.</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>16/00017</value>
</property>
<property>
<name>Title</name>
<url>http://localhost/locator.aspx?name=Common.Details.Navigate&amp;module=Case&amp;subtype=2&amp;recno=200017</url>
<value>San Case 16</value>
</property>
<property>
<name>Type</name>
<value>Case</value>
</property>
<property>
<name>Responsible person</name>
<value>Administrator</value>
</property>
<property>
<name>Responsible unit</name>
<value>Products</value>
</property>
<property>
<name>Status</name>
<value>In progress</value>
</property>
</properties>

更新2:将xml转换为json的代码如下。

xml2JsonInGridFormat: function xml2JsonInGridFormat(xml, visibleColoumns) {
if (xml.length > 0) {
var xmlDoc = $.parseXML(xml)
var result = {};
var colData = new Array();
var colNames = new Array();
var colModels = new Array();
//Build column Name
var NameProperties = xml[0].getElementsByTagName("name");
for (var j = 0; j < NameProperties.length; j++) {
var colName = NameProperties[j].childNodes[0].nodeValue;
colNames.push(colName);
}
//Build column Model
var Modelproperties = xml[0].getElementsByTagName("property");
for (var i = 0; i < Modelproperties.length; i++) {
var colModel = null;
colModel = {
'name': Modelproperties[i].getElementsByTagName("name")[0].childNodes[0].nodeValue,
sortable: true,
unformat: true,
shrinkToFit: false,
hidden: HideColumn(Modelproperties[i].getElementsByTagName("name")[0].childNodes[0].nodeValue, visibleColoumns),
width: "120px"
}
colModels.push(colModel);
}
//Build Row Data
for (var i = 0; i < xml.length; i++) {
var rows = xml[i].getElementsByTagName("property");
var row = {}
for (var j = 0; j < rows.length; j++) {
var cellKey = "", cellValue = "";
if (rows[j].getElementsByTagName("name")[0].childNodes[0] != undefined)
cellKey = rows[j].getElementsByTagName("name")[0].childNodes[0].nodeValue;
if (rows[j].getElementsByTagName("value")[0].childNodes[0] != undefined) {
if (rows[j].getElementsByTagName("url").length > 0)
cellValue = buildURL($(rows[j].getElementsByTagName("url")).text(), HtmlEncode($(rows[j].getElementsByTagName("value")).text()));
else
cellValue = HtmlEncode(rows[j].getElementsByTagName("value")[0].childNodes[0].nodeValue); //rows[j].getElementsByTagName("value")[0].childNodes[0].nodeValue;
}
row[cellKey] = cellValue;
}
colData.push(row);
}
result["ColNames"] = colNames;
result["ColModel"] = colModels;
result["colData"] = colData;
return result;
}
},

输出:

ass="ui-jqgrid-titlebar ui-jqgrid-caption ui-widget-header ui-corner-top ui-helper-clearfix" style="display: none;"><a role="link" class="ui-jqgrid-titlebar-close ui-corner-all HeaderButton" style="right: 0px;"><span class="ui-icon ui-icon-circle-triangle-n"></span></a><span class="ui-jqgrid-title"></span></div><div id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-state-default ui-jqgrid-toppager" dir="ltr" style="width: 750px;"><div id="pg_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-pager-control" role="group"><table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table" style="width:100%;table-layout:fixed;height:100%;" role="row"><tbody><tr><td id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager_left" align="left"><div dir="ltr" style="text-align:left" class="ui-paging-info">Display 1 of 5</div></td><td id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager_center" align="center" style="white-space:pre;"></td><td id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager_right" align="right" style="width: 262px;"><table cellspacing="0" cellpadding="0" border="0" style="table-layout:auto;" class="ui-pg-table"><tbody><tr><td id="first_t_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-first"></span></td><td id="prev_t_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-prev"></span></td><td class="ui-pg-button ui-state-disabled" style="width:4px;"><span class="ui-separator"></span></td><td dir="ltr">Page <input class="ui-pg-input" type="text" size="2" maxlength="7" value="0" role="textbox"> of <span id="sp_1_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager">1</span></td><td class="ui-pg-button ui-state-disabled" style="width:4px;"><span class="ui-separator"></span></td><td id="next_t_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-next"></span></td><td id="last_t_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_toppager" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-end"></span></td><td dir="ltr"><select class="ui-pg-selbox" role="listbox"><option role="option" value="5">5</option><option role="option" value="10">10</option><option role="option" value="25">25</option><option role="option" value="50">50</option></select></td></tr></tbody></table></td></tr></tbody></table></div></div><div class="ui-state-default ui-jqgrid-hdiv" style="width: 750px;"><div class="ui-jqgrid-hbox"><table class="ui-jqgrid-htable" style="width:750px" role="grid" aria-labelledby="gbox_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData" cellspacing="0" cellpadding="0" border="0"><thead><tr class="ui-jqgrid-labels" role="rowheader"><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px; display: none;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed" class="ui-jqgrid-sortable">Accessed<span class="s-ico" style=""><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no." role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no." class="ui-jqgrid-sortable">Case no.<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title" class="ui-jqgrid-sortable">Title<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type" class="ui-jqgrid-sortable">Type<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person" class="ui-jqgrid-sortable">Responsible person<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit" class="ui-jqgrid-sortable">Responsible unit<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 120px;"><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize;">&nbsp;</span><div id="jqgh_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status" class="ui-jqgrid-sortable">Status<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th></tr></thead></table></div></div><div class="ui-jqgrid-bdiv" style="height: auto; width: 750px;"><div style="position:relative;"><div></div><table id="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData" tabindex="0" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData" class="ui-jqgrid-btable" style="width: 750px;"><tbody><tr class="jqgfirstrow" role="row" style="height:auto"><td role="gridcell" style="height:0px;width:120px;display:none;"></td><td role="gridcell" style="height:0px;width:120px;"></td><td role="gridcell" style="height:0px;width:120px;"></td><td role="gridcell" style="height:0px;width:120px;"></td><td role="gridcell" style="height:0px;width:120px;"></td><td role="gridcell" style="height:0px;width:120px;"></td><td role="gridcell" style="height:0px;width:120px;"></td></tr><tr role="row" id="1" tabindex="0" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight" aria-selected="true"><td role="gridcell" style="display:none;" title="14.01.2016 12:20:08" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed">14.01.2016 12:20:08</td><td role="gridcell" style="" title="16/00017" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no."><a href="http://localhost/locator.aspxID=200017" target="_blank" style="text-decoration:underline;">16/00017</a></td><td role="gridcell" style="" title="San Case 16" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title"><a href="http://localhost/locator.aspxID=200017" target="_blank" style="text-decoration:underline;">San Case 16</a></td><td role="gridcell" style="" title="Case" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type">Case</td><td role="gridcell" style="" title="Admin" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person">Admin</td><td role="gridcell" style="" title="Product" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit">Product</td><td role="gridcell" style="" title="In progress" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status">In progress</td></tr><tr role="row" id="2" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="display:none;" title="14.01.2016 12:19:54" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed">14.01.2016 12:19:54</td><td role="gridcell" style="" title="16/00016" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no."><a href="http://localhost/locator.aspxID=200016" target="_blank" style="text-decoration:underline;">16/00016</a></td><td role="gridcell" style="" title="San Case 15" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title"><a href="http://localhost/locator.aspxID=200016" target="_blank" style="text-decoration:underline;">San Case 15</a></td><td role="gridcell" style="" title="Case" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type">Case</td><td role="gridcell" style="" title="Admin" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person">Admin</td><td role="gridcell" style="" title="Product" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit">Product</td><td role="gridcell" style="" title="In progress" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status">In progress</td></tr><tr role="row" id="3" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="display:none;" title="14.01.2016 12:19:41" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed">14.01.2016 12:19:41</td><td role="gridcell" style="" title="16/00015" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no."><a href="http://localhost/locator.aspxID=200015" target="_blank" style="text-decoration:underline;">16/00015</a></td><td role="gridcell" style="" title="San Case 14" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title"><a href="http://localhost/locator.aspxID=200015" target="_blank" style="text-decoration:underline;">San Case 14</a></td><td role="gridcell" style="" title="Case" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type">Case</td><td role="gridcell" style="" title="Admin" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person">Admin</td><td role="gridcell" style="" title="Product" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit">Product</td><td role="gridcell" style="" title="In progress" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status">In progress</td></tr><tr role="row" id="4" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="display:none;" title="14.01.2016 12:19:25" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed">14.01.2016 12:19:25</td><td role="gridcell" style="" title="16/00014" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no."><a href="http://localhost/locator.aspxID=200014" target="_blank" style="text-decoration:underline;">16/00014</a></td><td role="gridcell" style="" title="San Case 13" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title"><a href="http://localhost/locator.aspxID=200014" target="_blank" style="text-decoration:underline;">San Case 13</a></td><td role="gridcell" style="" title="Case" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type">Case</td><td role="gridcell" style="" title="Admin" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person">Admin</td><td role="gridcell" style="" title="Product" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit">Product</td><td role="gridcell" style="" title="In progress" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status">In progress</td></tr><tr role="row" id="5" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="display:none;" title="14.01.2016 12:19:07" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Accessed">14.01.2016 12:19:07</td><td role="gridcell" style="" title="16/00013" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Case no."><a href="http://localhost/locator.aspxID=200013" target="_blank" style="text-decoration:underline;">16/00013</a></td><td role="gridcell" style="" title="San Case 12" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Title"><a href="http://localhost/locator.aspxID=200013" target="_blank" style="text-decoration:underline;">San Case 12</a></td><td role="gridcell" style="" title="Case" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Type">Case</td><td role="gridcell" style="" title="Admin" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible person">Admin</td><td role="gridcell" style="" title="Product" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Responsible unit">Product</td><td role="gridcell" style="" title="In progress" aria-describedby="ctl00_ctl26_g_a1029eec_9a07_4328_bc41_c4aed6a95157_loadXMLData_Status">In progress</td></tr></tbody></table></div></div></div>

最佳答案

我不建议您在onPaging中实现一些复杂的分页逻辑。您使用的 XML 输入数据非常简单且非常小(大约 25 行)。相反,我建议您直接从服务器通过 URL 加载数据并使用 loadonce: true,它通知 jqGrid 立即读取所有数据,并将其保存在本地 data 中 属性并使用数据进行本地分页、排序和过滤。

The demo使用以下代码

$("#list").jqGrid({
datatype: "xml",
url: "SanjuRao.xml",
colNames: ["Name", "Value"],
colModel: [
{ name: "name" },
{ name: "value" }
],
cmTemplate: { autoResizable: true, width: 200 },
autoResizing: { compact: true },
iconSet: "fontAwesome",
rowNum: 5,
rowList: [5, 10, 25, "10000:All"],
viewrecords: true,
pager: true,
toppager: true,
rownumbers: true,
loadonce: true,
sortname: "name",
forceClientSorting: true,
xmlReader: {
root: "properties",
row: "property",
repeatitems: false
},
searching: {
closeAfterSearch: true,
searchOnEnter: true,
closeOnEscape: true,
multipleSearch: true,
multipleGroup: true,
defaultSearch: "cn"
}
})
.jqGrid("navGrid", { add: false, edit: false, del: false})
.jqGrid("filterToolbar");

它显示如下图所示的网格

enter image description here

它从服务器加载数据(从演示中的静态文件),在客户端对数据进行排序并显示第一页。如果您不需要顶部寻呼机,可以删除 toppager: true。人们可以使用过滤器工具栏来快速过滤数据(由 filterToolbar 添加),并使用搜索对话框来进行更复杂的数据过滤(由 navGrid 添加)。我用过free jqGrid在演示中。这是我开发的 jqGrid 的分支。它具有一些扩展功能,例如 forceClientSorting: true

更新:如果定义了url属性,要将value列显示为链接,您可以使用自定义格式化程序。您只需添加

additionalProperty: ["url"]

通知免费jqGrid读取输入数据的附加属性并使用列value的以下定义:

{
name: "value",
formatter: function (cellValue, options) {
var item = options.rowData;
if (item.url) {
return "<a class='mylink' href='" + item.url + "'>" + cellValue + "</a>";
} else {
return cellValue;
}
}
}

参见the modified demo ,其中 mylink 定义了链接的 CSS 样式。例如

.mylink {
text-decoration: underline;
}

显示的结果如下图所示

enter image description here

小评论。我包含了 mylink 类和 text-decoration: underline; CSS 规则的设置,只是因为我在演示中使用了 bootstrap.css 。如果您不需要 Bootstrap (jqGrid 不需要),则不需要执行此操作。

关于javascript - 我可以设置总页数并在单击下一页时使用 jq 网格中的 ajax 加载下一组记录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836512/

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