Auto select rows
Auto select rows
Hi, i've data stored on my db, i need to select some rows on datatable when data is loading. I tried do this in event:
$('#mesast').on( 'draw.dt', function () {
var table = $('#mesast').DataTable();
table
.column( 4 )
.data()
.each( function ( value, index ) {
if(value.length > 0){
// Seleccionar fila
$( table.row( index ).nodes() ).addClass( 'selected' );
}
} );
} );
And rows are correctly selected, but when i click some selected row, this row is not unselected until "second click" and when y save datatable in my db, some rows previously selected on load data, aren't saved...maybe that my auto-select is only "visual" effect, but datatable internally doesn't
Best regards,
Oscar
Answers
The
row().select()
method can be used to select a row.Allan
Thanks Allan for your quickly answer; only for test i tried:
$('#mesast').on( 'draw.dt', function () {
var table = $('#mesast').DataTable();
but console return: "Uncaught TypeError: table.row(...).select is not a function"
Thanks,
I'm Sorry Allan, I just include css and js required files and select() method work, but:
var oTT = TableTools.fnGetInstance( 'mesast' );
var aSelectedTrs = oTT.fnGetSelectedData();
aSelectedTrs not return rows previously selected when i reload data, only returns rows selected by "click" or "select buttons". I use fnGetSelectedData() in order to get udated rows selected.
Thanks in advance.
I would suggest not mixing TableTools and Select. They are two difference pieces of software. I would also not suggest using TableTools - it is legacy and no longer being updated.
Select is the way to do it. If you want to get the selected rows, that is documented here.
Allan
Important detail...... now i'm not using TableTools, and all work fine..!, thank you Allan!!
OSM