My challenge involves extracting data from a Kendo grid using the following JavaScript call:
var data = JSON.stringify($(".k-grid").data("kendoGrid").dataSource.data())
This retrieves all properties in the C# class for the records. There are three properties that were not displayed in the Kendo presentation but are being included in this call (and subsequently passed on to an Export to CSV function).
I am seeking guidance on how to exclude these specific columns from the data extraction.
EDIT:
After reviewing @DontVoteMeDown's advice, I attempted to create a function for this purpose:
function removeKeys(data) {
let excludedKeys = ['InvoiceId', 'IsOk', 'ErrorMessage'];
let newData = data.map((item) => {
let newObj = {};
Object.keys(item).forEach(key => {
if (excludedKeys.indexOf(key) == -1) {
newObj[key] = item[key];
}
});
return newObj;
});
}
However, when running the code in the Console debugger, an error is encountered.
When executing the sequence like this, I face an issue with 'data' returning undefined:
var tableData = $(".k-grid").data("kendoGrid").dataSource.data();
var dataChop = removeKeys(tableData);
var data = JSON.stringify(dataChop);
By rearranging the steps as follows, I receive an error stating 'data.map is not a function':
var tableData = $(".k-grid").data("kendoGrid").dataSource.data();
var dataFull = JSON.stringify(tableData);
var data = removeKeys(dataFull);
What would be the correct approach to invoke this mapping function successfully?