Using Button.ExportData( ), How to export specific rows which satisfy a condition.
Using Button.ExportData( ), How to export specific rows which satisfy a condition.
ShaibaazS
Posts: 7Questions: 3Answers: 0
Dear Sir,
I have DataTable with multiple Rows. And I am using Button.ExportData( ) function to export the rows from DataTable and send it to server side. I am able to export all the rows but I am not able to export rows which satisfy a condition. For eg. I have DataTable with columns Id, Paid, Diff, Remarks. I want to export rows with Id=2. Hope you can help me out.
Thanks in advance.
Happy Coding.
This discussion has been closed.
Answers
Dear Sir,
As a Test Case: I have the following code:
// Initialized DataTable.
var parent = $('#tblParent').DataTable();
// Using buttons.exportData() to get rows from DataTable to be exported to Server Side , returns Header, Body, Footer
var parentData = parent.buttons.exportData();
// Getting only the Body part
var arrParent = $.map(parentData, function (value, index) {
return [value];
});
// The above code works perfectly but was trying something like:
var parentData = parent.buttons.exportData({
format: {
body: function (data, column, row, node) {
return data[0].value === 2;
}
}
});
// which would return only rows that satisfy a condition( like Id column with value 2)
The
buttons.exportData()
method allows arows
property to be defined - that is arow-selector
, which can be given as a function. That function can then be used to perform whatever logic check you require to include the row or not.Allan
Dear Allan,
Can you give an example.
I have tried something like this :
var parentData = parent.buttons.exportData({
format: {
body: function (data, column, row, node) {
return data[0].value === 2;
}
}
});
But I am not able to get desired result. This should return all the rows where Id = 2.
Assuming your are loading objects which have an
Id
property you would use:return data.Id === 2;
.Allan
Thank you Allan,
It returns false for every value of the property.
Can you help.
Yes, if you give me a link to the page showing the issue I would be happy to help debug it.
Allan