Is there an option to export selected rows? I need to be able to do this with paging/sorting/filtering set to Remote and with no primary key defined on the grid.
Hi Kevin,
thank you for sharing your solution here, so that others community members can benefit from it as well !
Never mind, got it, it's the primaryKey property, set on the grid itself. For anyone interested, the following callback worked:
rowExporting: function (sender, args) { var rid = args.rowId; var select = $("#jobs").igGridSelection("selectedRows"); for (var i = 0; i < select.length; i++) { if (select[i].id === rid) { return true; } } return false;
A few notes, as it still took me a bit of fiddling to get it working:
Hope you don't mind if I hijack this thread, but we're trying to do the same thing (export selected rows to Excel). I tried using the following code:
$("#exportSelectedButton").on("click", function () { $.ig.GridExcelExporter.exportGrid($('#jobs'), { gridFeatureOptions: { sorting: "applied", paging: "allRows", hiding: "none", filtering: "filteredRowsOnly" }, columnsToSkip: ["ContactUrl"] }, { cellExported: function (e, args) { if (args.columnKey == 'ViewUrl') { var regex = /<[^>]*>([^<]*)</; var raw = args.cellValue; var text = regex.exec(raw); text = (text == null ? raw : text[1]); args.xlRow.cells(args.columnIndex).value(text); } }, rowExporting: function (sender, args) { var rid = args.rowId; var select = $("#jobs").igGridSelection("selectedCells"); for (var i = 0; i < select.length; i++) { if (select[i].rowId === rid) return false; } return true; } }); });
The idea being to match rows from the source data that were also present in the selected rows array - if the row being tested for export is in that array then export it, otherwise don't. However, when this runs it exports everything because the rowId values haven't been populated. I'm sure somewhere there is an option to specify how this is populated, but I can't find it. Can you first of all tell me if my approach above makes sense, and if so then point me at how to populate rowId?
Thanks,
Kevin
Hi Julie,
By default the igGridExcelExporter is working with the grid data available on the client. If you want to export only the selected rows, you will need to handle this manually. This can be done in the exportStarting event, where to pass a data object containing only the selected rows records:
$.ig.GridExcelExporter.exportGrid($("#report-grid"), { fileName: "igGrid", gridFeatureOptions: { "sorting": "applied" }, }, { exportStarting: function (args) { // pass the data object containing only the selected rows records args._gridData = newData; } });
If you need help on how to retrieve only the selected rows data, please let me know what is the data source for the grid and I will be able to provide assistance.