datatable
datatable copied to clipboard
What is the best way to get data from the selected rows?
I'm guessing I can probably make use of this: https://github.com/frappe/datatable/blob/31264d1f4da9445c147fdc1060914aa44fa440fa/src/filterRows.js#L3-L30
But it's unclear how I could get the rows that are selected, idiomatically at least, using this library.
It might be a useful addition to the API to add a getSelectedRows
function following this one: https://github.com/frappe/datatable/blob/master/src/datatable.js#L174-L176
Any suggestions appreciated.
Bingo, https://github.com/frappe/datatable/blob/67f9717827f5d960cb01f523d2f2943106b55680/src/rowmanager.js#L74-L88
I'd suggest documentation on this. I will try to submit an MR for this.
Also it's still pretty unclear, at least to me how to use the filterRows
function. Again, once I get examples I'd be glad to contribute. Although it doesn't look like the docs are in this repo.
I had a situation where I wanted to get the selected data out an initial datatable object and move it to a new datatable. Getting that data out of the datatable object feels a little clunky, at least the way I did it:
function getSelectedRows(datatable) {
console.log("getSelectedRows")
console.log(datatable.options.data);
console.log(datatable.rowmanager.getCheckedRows());
var selectData = datatable.rowmanager.getCheckedRows().map(x => datatable.options.data[parseInt(x)]);
console.log(selectData);
return selectData
}
Any suggestions appreciated, in terms of a better way to do this.