row().select() with select extension on initComplete (Uncaught TypeError:)
row().select() with select extension on initComplete (Uncaught TypeError:)
Hi All,
Using Datatables 1.10.9 and the select extension version 1.0.1 with Bootstrap 3.3.5
My intention is to select a row after a page refresh with the api using the select extension.
...
"stateSave": true,
"stateDuration": 60*60*24,
"select": {
style: 'single'
},
"initComplete": function(settings, json) {
console.log( 'DataTables has finished its initialisation.' );
table.row( ':eq(0)', { page: 'current' } ).select()
}
This returns an error:
Uncaught TypeError: Cannot read property 'style' of undefined
dataTables.select.min.js:8
Same error with using row-selector (int), for example: table.row(0).select()
Am I missing something or is it a bug?
Sorry for not providing an example but live.datatables.net is down since yesterday morning.
Replies
Join of the question.
In the mean time I found out that accessing live.datatables.net with Chrome and OS X 10.9. 5 responds with "DataTables live test page is currently offline." every time. With safari I noticed some unexpected behaviour. Finally Firefox was OK.
Then adding library Select 1.0.0 or 1.0.1.dev with following code
will result in console message:
http://live.datatables.net/fezodoza/1/
Still looking for an answer on the initial question how to use extension select with table.row().select()?
I've got the exact same error message with the following code. Also using Datatables 1.10.9, select extension version 1.0.1, Bootstrap 3.3.5.
Any help or resolution would be greatly appreciated, thanks!
I just noticed that the selection of rows works for me if I use the following code:
Of course this implementation is not the desired way. I'd like to select all rows as soon as the table is loaded.
Here is an updated version of your live.datatables.net code which works. The only change I made was to change the file load order (jQuery, DataTables then Select).
Can you update it to show the issue so I can debug it?
Allan
Hi Allan,
Oeps didn't even think about wrong order of scripts (assumed that live.datatables.net would have taken care of inserting (Add Library) using the correct order).
Anyway, version with code added
Adding setTimeout makes select based on
':eq(0)'
work.Using
table.row(1).select();
won't work, but if I'm not mistaken the docs state that row-selector can also be an integer value.Since the "saveState" will not return to last selected row, my final goal is to automatically return to last selection after page-refresh or when returning to the page. In the table I have the field some_id which is stored to localStorage this unique value is fetched then I need to get the corresponding row index and select row.
You would think that won't you - but I've never been able to persuade it to do that...
Regarding the issue you are seeing - thanks for the test case - hugely appreciated!
There are two issues in it:
table.row...
- the issue here is thatinitComplete
will execute at the very end of the DataTables initialisation, but before it has returned. i.e.table
will be undefined. This isn't an issue if you use Ajax, but for DOM tables like in the example, to access the API ininitComplete
you need to usethis.api().row...
.Updated and working example: http://live.datatables.net/fezodoza/4/edit
Allan
Thank you allan.
Well you noticed, no Javascript ninja on this side :')
When trying your update, the Row index selector (int),
this.api().row(1).select();
there is still no selection made..Am I missing something?
http://live.datatables.net/fezodoza/5/
should be:
http://live.datatables.net/fezodoza/7/edit
Also note that row data index 1 is on the second page of the table with default sorting.
Allan