Reputation: 59
I'm using the latest free jqGrid (pulled today). I'm using columnChooser. By default I load all available columns to the grid. I use columnChooser to remove a few columns. This works great.
I use getRowData() to export the grid data. This works great, even maintaining my filters and sorting. But getRowData always returns all the columns, even when I remove them using columnChooser.
How can I make getRowData include just the columns visible in the grid? I've tried reload, and remapColumns without success.
$('#iown').jqGrid('navButtonAdd', '#iownpager', { caption: "", buttonicon: "ui-icon-calculator", onClickButton: function () {
$('#iown').jqGrid('columnChooser',{modal: true, width: 550,
done : function(perm) {
if (perm) {
$('#iown').jqGrid("remapColumns", perm, true);
}
}
});
},
title: "Choose columns"
});
$("#iown").jqGrid('navButtonAdd','#iownpager', { caption: '', buttonicon: 'ui-icon-disk', onClickButton: function () {
var gridData = jQuery("#iown").getRowData();
var postData = JSON.stringify(gridData);
JSONToCSVConvertor(postData, report, true);
},
title: 'Download Current Grid View',
id: 'iown-dl'
});
Thank you, Mike
Upvotes: 0
Views: 398
Reputation: 221997
The problem seems to me independent from columnChooser
. You use just getRowData
which return the data from all columns, inclusive hidden columns, of the current page.
I suggest you to replace usage of getRowData
to the following code
var iCol, $grid = $("#iown"), colModel = $grid.jqGrid("getGridParam", "colModel"),
idPrefix = $grid.jqGrid("getGridParam", "idPrefix"), tr, td, cm, cmName, item,
nCols = colModel.length, rows = $grid[0].rows, iRow, nRows = rows.length, data = [];
for (iRow = 0; iRow < nRows; iRow++) {
tr = rows[iRow];
if ($(tr).hasClass("jqgrow")) {
item = {}; // item of returned data
for (iCol = 0; iCol < nCols; iCol++) {
cm = colModel[iCol];
cmName = cm.name;
if (!cm.hidden && cmName !== "cb" && cmName !== "subgrid" && cmName !== "rn" && cm.formatter !== "actions") {
td = tr.cells[iCol];
try {
item[cmName] = $.unformat.call($grid[0], td, { rowId: tr.id, colModel: cm }, iCol);
} catch (exception) {
item[cmName] = $.jgrid.htmlDecode($(td).html());
}
}
}
item.id = $.jgrid.stripPref(idPrefix, tr.id);
data.push(item);
}
}
The code fills data
array with the data from the grid and works very close to getRowData
method. I added only additional test for hidden
property of the column, which you need, removed some code required for TreeGrid only and added setting of id
property.
Upvotes: 2