jqGrid摘要页脚是否可以在没有userdata服务器请求的情况下填充?
我已经详细讨论了这个网站上提出的每一个与填充jqGrid摘要页脚相关的问题,而用户数据不是服务器请求。和jqGrid wiki资源,只是找不到答案。这可能吗 我以许多典型的方式使用jqGrid作为我的管理门户的一部分,但有一个特殊的用途,我希望jqGrid的外观和感觉从一开始就是一个空的UI容器,用于一些用户交互,通过表单添加行,而表单在提交时不会发布(感谢下面的Oleg很棒的脚本)但只需添加行并使用新添加行中的值更新摘要页脚。我在colModel中有'summarytype:'sum','grouping:true',footerrow:true,userDataOnFooter:true,altRows:true,在网格选项中,但是除了本地数据字符串中的userdata提供的初始值之外,summary footer值永远不会更改。似乎没人想触及这个话题。是因为jqGrid的主要本质是数据库驱动的功能吗?我以数据库驱动的姿态使用了大约15个jqGrid实例(其中许多实例现在都在生产服务中),但出于一致性考虑(我的所有UI都在JQTab中),最初需要将其作为客户端UI使用,而不需要服务器请求(所有内容将稍后保存到db中)但是,我正在竭尽全力尝试仅在客户端上以编程方式操纵摘要页脚。有人能建议如何在添加新行时更新摘要页脚的值吗?新行的值将与任何现有行进行汇总,并且不涉及任何向服务器的发布,只在网格内更新 提供的代码有点长,主要基于用户Oleg的解决方案,该解决方案用于从模式表单添加一行,而无需发布到服务器。我已经将本地数组数据更改为JSON字符串,只是为了更好地理解表示法,因为我已经习惯了xml。jsonstring使用一个默认行初始化网格,供用户编辑。我省略了jsonReader,因为网格无法使用它进行渲染 简而言之,我想做的是在网格中添加新行(此时没有向服务器发布)或编辑或删除新行时更新摘要页脚。当达到某一组值时,显示的按钮会提示用户将行数据保存到dbjqGrid摘要页脚是否可以在没有userdata服务器请求的情况下填充?,jqgrid,footer,summary,user-data,Jqgrid,Footer,Summary,User Data,我已经详细讨论了这个网站上提出的每一个与填充jqGrid摘要页脚相关的问题,而用户数据不是服务器请求。和jqGrid wiki资源,只是找不到答案。这可能吗 我以许多典型的方式使用jqGrid作为我的管理门户的一部分,但有一个特殊的用途,我希望jqGrid的外观和感觉从一开始就是一个空的UI容器,用于一些用户交互,通过表单添加行,而表单在提交时不会发布(感谢下面的Oleg很棒的脚本)但只需添加行并使用新添加行中的值更新摘要页脚。我在colModel中有'summarytype:'sum','gr
var lastSel, mydata = { "total": 1, "page": 1, "records": 1, "rows": [{ "id": acmid, "cell": ["0.00", "0.00", "0.00", "0.00"]}], "userdata":{ "mf": 0.00, "af":0.00,"pf":0.00,"cf":0.00 }}
grid = $("#ta_form_d"),
onclickSubmitLocal = function (options, postdata) {
var grid_p = grid[0].p,
idname = grid_p.prmNames.id,
grid_id = grid[0].id,
id_in_postdata = grid_id + "_id",
rowid = postdata[id_in_postdata],
addMode = rowid === "_empty",
oldValueOfSortColumn;
// postdata has row id property with another name. we fix it:
if (addMode) {
// generate new id
var new_id = grid_p.records + 1;
while ($("#" + new_id).length !== 0) {
new_id++;
}
postdata[idname] = String(new_id);
//alert(postdata[idname]);
} else if (typeof (postdata[idname]) === "undefined") {
// set id property only if the property not exist
postdata[idname] = rowid;
}
delete postdata[id_in_postdata];
// prepare postdata for tree grid
if (grid_p.treeGrid === true) {
if (addMode) {
var tr_par_id = grid_p.treeGridModel === 'adjacency' ? grid_p.treeReader.parent_id_field : 'parent_id';
postdata[tr_par_id] = grid_p.selrow;
}
$.each(grid_p.treeReader, function (i) {
if (postdata.hasOwnProperty(this)) {
delete postdata[this];
}
});
}
// decode data if there encoded with autoencode
if (grid_p.autoencode) {
$.each(postdata, function (n, v) {
postdata[n] = $.jgrid.htmlDecode(v); // TODO: some columns could be skipped
});
}
// save old value from the sorted column
oldValueOfSortColumn = grid_p.sortname === "" ? undefined : grid.jqGrid('getCell', rowid, grid_p.sortname);
//alert(oldValueOfSortColumn);
// save the data in the grid
if (grid_p.treeGrid === true) {
if (addMode) {
grid.jqGrid("addChildNode", rowid, grid_p.selrow, postdata);
} else {
grid.jqGrid("setTreeRow", rowid, postdata);
}
} else {
if (addMode) {
grid.jqGrid("addRowData", rowid, postdata, options.addedrow);
} else {
grid.jqGrid("setRowData", rowid, postdata);
}
}
if ((addMode && options.closeAfterAdd) || (!addMode && options.closeAfterEdit)) {
// close the edit/add dialog
$.jgrid.hideModal("#editmod" + grid_id,
{ gb: "#gbox_" + grid_id, jqm: options.jqModal, onClose: options.onClose });
}
if (postdata[grid_p.sortname] !== oldValueOfSortColumn) {
// if the data are changed in the column by which are currently sorted
// we need resort the grid
setTimeout(function () {
grid.trigger("reloadGrid", [{ current: true}]);
}, 100);
}
// !!! the most important step: skip ajax request to the server
this.processing = true;
return {};
},
editSettings = {
//recreateForm:true,
jqModal: false,
reloadAfterSubmit: false,
closeOnEscape: true,
savekey: [true, 13],
closeAfterEdit: true,
onclickSubmit: onclickSubmitLocal
},
addSettings = {
//recreateForm:true,
jqModal: false,
reloadAfterSubmit: false,
savekey: [true, 13],
closeOnEscape: true,
closeAfterAdd: true,
onclickSubmit: onclickSubmitLocal
},
delSettings = {
// because I use "local" data I don't want to send the changes to the server
// so I use "processing:true" setting and delete the row manually in onclickSubmit
onclickSubmit: function (options, rowid) {
var grid_id = grid[0].id,
grid_p = grid[0].p,
newPage = grid[0].p.page;
// delete the row
grid.delRowData(rowid);
$.jgrid.hideModal("#delmod" + grid_id,
{ gb: "#gbox_" + grid_id, jqm: options.jqModal, onClose: options.onClose });
if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
// if after deliting there are no rows on the current page
// which is the last page of the grid
newPage--; // go to the previous page
}
// reload grid to make the row from the next page visable.
grid.trigger("reloadGrid", [{ page: newPage}]);
}
return true;
},
processing: true
}; //,
/*initDateEdit = function (elem) {
setTimeout(function () {
$(elem).datepicker({
dateFormat: 'dd-M-yy',
autoSize: true,
showOn: 'button', // it dosn't work in searching dialog
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
//$(elem).focus();
}, 100);
},
initDateSearch = function (elem) {
setTimeout(function () {
$(elem).datepicker({
dateFormat: 'dd-M-yy',
autoSize: true,
//showOn: 'button', // it dosn't work in searching dialog
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
//$(elem).focus();
}, 100);
};*/
//jQuery("#ta_form_d").jqGrid({
grid.jqGrid({
// url:'/admin/tg_cma/ta_allocations.asp?acmid=' + acmid + '&mid=' + merchantid + '&approval_code=' + approval_code,
//datatype: "local",
//data: mydata,
datatype: 'jsonstring',
datastr: mydata,
colNames: ['ID', 'Monthly Fees', 'ATM Fees', 'POS Fees', 'Card to Card Fees'],
colModel: [
{ name: 'id', index: 'id', width: 90, align: "center", editable: true, editoptions: { size: 25 }, formoptions: { rowpos: 1, colpos: 1, label: "EzyAccount ID", elmprefix: "(*) " }, editrules: { required: true} },
{ name: 'mf', index: 'mf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 2, colpos: 1, label: "Monthly Fee", elmprefix: "(*) " }, editrules: { required: true} },
{ name: 'af', index: 'af', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 3, colpos: 1, label: "ATM Fee", elmprefix: "(*) " }, editrules: { required: true} },
{ name: 'pf', index: 'pf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 4, colpos: 1, label: "POS Fee", elmprefix: "(*) " }, editrules: { required: true} },
{ name: 'cf', index: 'cf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 5, colpos: 1, label: "Card to Card Fee", elmprefix: "(*) " }, editrules: { required: true} }
],
rowNum: 5,
rowList: [5, 10, 20],
pager: '#pta_form_d',
toolbar: [true, "top"],
width: 500,
height: 100,
editurl: 'clientArray',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
multiselect: false,
cellEdit: false,
caption: "Allocations",
grouping: true,
/*groupingView: {
groupField: ['id', 'mf', 'af', 'pf', 'cf'],
groupColumnShow: [true],
groupText: ['<b>{0}</b>'],
groupCollapse: false,
groupOrder: ['asc'],
groupSummary: [true],
groupDataSorted: true
},*/
footerrow: true,
userDataOnFooter: true,
altRows: true,
ondblClickRow: function (rowid, ri, ci) {
var p = grid[0].p;
if (p.selrow !== rowid) {
// prevent the row from be unselected on double-click
// the implementation is for "multiselect:false" which we use,
// but one can easy modify the code for "multiselect:true"
grid.jqGrid('setSelection', rowid);
}
grid.jqGrid('editGridRow', rowid, editSettings);
},
onSelectRow: function (id) {
if (id && id !== lastSel) {
// cancel editing of the previous selected row if it was in editing state.
// jqGrid hold intern savedRow array inside of jqGrid object,
// so it is safe to call restoreRow method with any id parameter
// if jqGrid not in editing state
if (typeof lastSel !== "undefined") {
grid.jqGrid('restoreRow', lastSel);
}
lastSel = id;
}
},
afterEditCell: function (rowid, cellname, value, iRow, iCol) {
alert(iCol);
},
gridComplete: function () {
},
loadComplete: function (data) {
}
})
.jqGrid('navGrid', '#pta_form_d', {}, editSettings, addSettings, delSettings,
{ multipleSearch: true, overlay: false,
onClose: function (form) {
// if we close the search dialog during the datapicker are opened
// the datepicker will stay opened. To fix this we have to hide
// the div used by datepicker
//$("div#ui-datepicker-div.ui-datepicker").hide();
}
});
$("#t_ta_form_d").append("<input type='button' class='add' value='Add New Allocation' style='height:20px; color:green; font-size:11px;' />");
$("input.add", "#t_ta_form_d").click(function () {
jQuery("#ta_form_d").jqGrid('editGridRow', "new", {
//recreateForm:true,
jqModal: false,
reloadAfterSubmit: false,
savekey: [true, 13],
closeOnEscape: true,
closeAfterAdd: true,
onclickSubmit: onclickSubmitLocal
})
})
var lastSel,mydata={“total”:1,“page”:1,“records”:1,“rows”:[{“id”:acmid,“cell”:[“0.00”,“0.00”,“0.00”,“0.00”],“userdata”:{“mf”:0.00,“af”:0.00,“pf”:0.00,“cf”:0.00}
网格=$(“#ta#u form_d”),
onclickSubmitLocal=函数(选项,postdata){
var grid_p=grid[0].p,
idname=grid_p.prmNames.id,
grid\u id=grid[0]。id,
id\u in\u postdata=grid\u id+“\u id”,
rowid=postdata[id\u in\u postdata],
addMode=rowid==“\u empty”,
OrtValueofSortColumn;
//postdata具有另一个名称的行id属性。我们修复了它:
如果(添加模式){
//生成新id
var new_id=网格p.records+1;
while($(“#”+新的_id).length!==0){
新的_id++;
}
postdata[idname]=字符串(新的\u id);
//警报(postdata[idname]);
}else if(typeof(postdata[idname])=“未定义”){
//仅当属性不存在时才设置id属性
postdata[idname]=rowid;
}
删除postdata[id_in_postdata];
//为树状网格准备postdata
if(grid_p.treeGrid==true){
如果(添加模式){
var tr_par_id=grid_p.treeGridModel===‘邻接’?grid_p.treeReader.parent_id_字段:‘parent_id’;
postdata[tr_par_id]=网格p.selrow;
}
美元每台(网格p.treeReader,功能(i){
if(postdata.hasOwnProperty(this)){
删除postdata[this];
}
});
}
//如果存在使用自动编码编码的编码,则对数据进行解码
if(网格自动编码){
$。每个(postdata,函数(n,v){
postdata[n]=$.jgrid.htmlDecode(v);//TODO:可以跳过某些列
});
}
//保存排序列中的旧值
oldValueOfSortColumn=grid\u p.sortname==“”?未定义:grid.jqGrid('getCell',rowid,grid\u p.sortname);
//警报(OrdValueOfSortColumn);
//将数据保存在网格中
if(grid_p.treeGrid==true){
如果(添加模式){
jqGrid(“addChildNode”,rowid,grid_p.selrow,postdata);
}否则{
jqGrid(“setTreeRow”,rowid,postdata);
}
}否则{
如果(添加模式){
jqGrid(“addRowData”,rowid,postdata,options.adddrow);
}否则{
jqGrid(“setRowData”,rowid,postdata);
}
}
if((addMode&&options.closeAfterAdd)| |(!addMode&&options.closeAfterEdit)){
//关闭“编辑/添加”对话框
$.jgrid.hideModal(“#editmod”+网格id,
{gb:#gbox_uuu“+grid_uid,jqm:options.jqModal,onClose:options.onClose});
}
if(postdata[grid\u p.sortname]!==oldValueOfSortColumn){
//如果数据在当前排序依据的列中发生更改
//我们需要电网
setTimeout(函数(){
trigger(“reloadGrid”,[{current:true}]);
}, 100);
}
//!!!最重要的一步:跳过对服务器的ajax请求
这是真的;
返回{};
},
编辑设置={
//再现形式:正确,
jqModal:false,
reloadAfterSubmit:false,
closeOnEscape:没错,
savekey:[true,13],
closeAfterEdit:true,
onclickSubmit:onclickSubmitL