Sélect all onload
Sélect all onload
gmisterk
Posts: 4Questions: 2Answers: 0
Hi all
I use select extension .
I have a button selectAll. .and It works fine.
By défaut nothing is selected and I want inverse.
I.m trying to select all items onload (when document ready)
I have tried this : $('#myid').addClass('selected'); but whiout success
Any suggestion?
Thanks for your Help.
This discussion has been closed.
Answers
Hi @gmisterk ,
The best bet is to use
initComplete
, this will get called when the table has fully loaded. You can do something like this:See this live example.
Cheers,
Colin
This was very helpful in getting me started. Any suggestions on how to have it select only specific rows instead of all?
My objective is that I'm setting this up for a user to UPDATE an existing record in the database. I have the complete form loaded and pre-populated with the existing database values.
What I need to accomplish is now AFTER LOAD my datatable shows all US States but I need to auto select New York and California. My JSON that populates the datatable has an additional attribute name 'active' which is set to '1' for the rows I'd like to auto select.
Any ideas?
Good question. The solution I would use makes use of
rows().indexes()
andfilter()
. InsideinitComplete
a combo of those APIs is used to build an array of indexes containing the rows withactive === 1
. The indexes is then used to select the rows to select usingrows().select()
. Here is an example selecting all rows where the Office isLondon
.http://live.datatables.net/ketaripi/1/edit
Kevin