Is there any way to get selected rows in Datatable?
Used checkboxColumn: true mentioned in below link
https://github.com/frappe/datatable/issues/59
But how to get row Ids, that is selected?
What is the Event to capture selected rows?
Thanks in Advance…
shahid
December 13, 2019, 12:33pm
2
@hetal1110 have you achieved this?
sanjay
December 13, 2019, 2:06pm
3
Try below :
let selected_rows = cur_frm.doc["item"].grid.get_selected() ;
shahid
December 14, 2019, 6:25am
4
@sanjay thanks for your reply,
are you talking about query/ script report view or child table view?
This is what i’ve tried.
frappe.query_reports["Testing"] = {
onload: function(report) {
report.page.add_inner_button(__("Test"), function() {
let selected_rows = cur_frm.doc["item"].grid.get_selected();
console.log(selected_rows);
});
},
get_datatable_options(options) {
return Object.assign(options, {
checkboxColumn: true
});
}
};
but getting below error:
VM1924:5 Uncaught TypeError: Cannot read property 'doc' of null
at <anonymous>:5:32
at HTMLButtonElement.i (page.js:452)
at HTMLButtonElement.dispatch (jquery.min.js:3)
at HTMLButtonElement.r.handle (jquery.min.js:3)
sanjay
December 14, 2019, 12:40pm
5
For report having checkbox, you can get selected row as mentioned below:
frappe.query_report.page.add_inner_button(__("Test"), function() {
var selected_rows = [];
$('.dt-scrollable').find(":input[type=checkbox]").each((idx, row) => {
if(row.checked){
selected_rows.push(frappe.query_report.data[idx]);
}
});
});
Hi. Thanks for your solution, it helped me, but it is not right. After scrolling, indexes are different, you need to do following…
$('.dt-scrollable').find(":input[type=checkbox]").each((idx, row) => {
if(row.checked){
selected_rows.push(frappe.query_report.data[$(row.closest(".dt-cell")).data("row-index")]);
}
});
sanjay
August 4, 2020, 9:21am
7
Thank you to rectify the issue.
But, this is still not good solution, check thread:
Hi,
i had custom script report and i am trying to get all selected rows, I had this part of code, which is partially working:
$('.dt-scrollable').find(":input[type=checkbox]").each((idx, row) => {
if(row.checked){
console.log(row.closest(".dt-cell"));
console.log($(row.closest(".dt-cell")).data("row-index"));
}
});
But, this code will return only rendered rows. And when i click mark all rows, i will get only 25 rendered. Is there way how to return all of them?
In:
…
sanjay
August 6, 2020, 11:34am
9
So what result are you expecting ?
When you have table with 100 rows, you will select all of them, you will get only 25 rows which are rendered actually. I need all of selected rows.
where i to put this code i also need the child table selected row
this code mention i have to mention in child table or parent function can you plz help me
var selectedItems = frm.doc.child_table_name.filter(item => item.__checked);
selectedItems.map(row => ({//your code})
1 Like