take checkbox state from different Datatable pages
take checkbox state from different Datatable pages
GianlucaP
Posts: 2Questions: 1Answers: 0
As title I need to build a list of checked element of table that are distribuited in different pages:
I try the following code:
var dt = $('#ElementTable').DataTable();
var info = dt.page.info();
for(i=0;i<info.pages;i++)
{
console.log("pagina ("+(i+1)+"): ");
pdt = dt.page(i).rows().data();
pdt.rows().data().each(
function(row, index)
{
console.log(" riga ("+(index+1)+"): ");
$(row[0]).each(function(pos, elem)
{
var isSelected = $("#"+elem.id).prop('checked');
if(pos == 0)
console.log(" >> "+elem.type+": "+elem.checked+" / "+isSelected);
});
});
}
What I obtain con console is false for each chebox element in dataTable (also for elements that are checked), isSelected works only for the current page, but it is undefined for element that are in other datatable pages,
what can I do?
Thanks for your help
This discussion has been closed.
Answers
Hi @GianlucaP ,
This example here should help. A lot of your code is complicating things and unnecessary - for example
dt.page(1).rows()
isn't doing what you think it's doing, that will actually return all rows across all pages aspage()
returns a full API instance.Cheers,
Colin
Hi, thanks to your answer, unfortunately it still not working, I tried the same example and count remains always to 0.
My checkbuttons are made with materialize (I think that it doesn't matter, but there aren't other difference with the example)
We're happy to take a look, but could you link to your page or a generate a test case so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin