JQGrid(action, caption, 920, 400, loadtext);
function columnsData(Data) {
var str = "[";
for (var i = 0; i < Data.length; i++) {
str = str + "{name:'" + Data[i] + "', index:'" + Data[i] + "', editable: true}";
if (i != Data.length - 1) {
str = str + ",";
}
}
str = str + "]";
return str;
}
function JQGrid(action, caption, width, height, loadtext) {
var grid = $("#tblGrid");
var lastsel;
var editurl = '/PayInvoice/GridSave';
$.ajax({
url: action,
dataType: "json",
mtype: 'POST',
beforeSend: function () {
$("#dvloading").show();
},
success: function (result) {
if (result) {
if (!result.Error) {
var colData = columnsData(result.column);
colData = eval('{' + colData + '}');
grid.jqGrid('GridUnload');
grid.jqGrid({
url: action,
datatype: 'json',
mtype: 'POST',
colModel: colData,
colNames: result.column,
// multiselect: true,
width: width,
height: height,
rowNum: 20,
rowList: [20, 40, 60],
loadtext: loadtext,
pager: '#tblGridpager',
sortorder: "asc",
viewrecords: true,
gridview: true,
altRows: true,
cellEdit: true,
cellsubmit: "remote",
cellurl: '/PayInvoice/GridSavecell',
beforeSubmitCell: function (id, cellname, value, iRow, iCol) {
objedit(id, cellname, value);
return { id: id, cellname: cellname, value: value, iRow: iRow, iCol: iCol };
},
afterSaveCell: function (id, cellname, value, iRow, iCol) {
objedit(id, cellname, value);
return { id: id, cellname: cellname, value: value, iRow: iRow, iCol: iCol };
},
caption: caption
});
}
}
},
error: function (xhr, ajaxOptions, thrownError) {
if (xhr && thrownError) {
alert('Status: ' + xhr.status + ' Error: ' + thrownError);
}
}, complete: function () {
$("#dvloading").hide();
}
});
}
function objedit(id, cellname, value) {
var flag = 0;
for (var i = 0; i < index; i++) {
if (obj[i][0] == id && obj[i][1] == cellname) {
obj[i] = [id, cellname, value]
flag++;
}
}
if (flag == 0) {
obj[index] = [id, cellname, value];
index++;
}
}
JQGrid1.Columns.FromDataField(ColumnName).Visible = false;
JQGrid1.Columns.FromDataField(ColumnName).HeaderText = "Sample";
$("#grid").showCol("Link");
$("#grid").hideCol("Link");
$("#grid").trigger("reloadGrid");
No comments:
Post a Comment