Select Extension: How to select first row on init and how to get at least one row selected.
Select Extension: How to select first row on init and how to get at least one row selected.
StefanB
Posts: 2Questions: 2Answers: 0
Hello,
I'm new to DataTables and have two questions.
- Is it possible to select the first row automatically when the DataTable is initialized?
- At the moment it is possible, that the user deselect an item by clicking on it. I want, that at least one row keeps selected. When the user clicks to the selected row, the selection should not be removed.
This is my initialization of my DataTable:
`var dataTableOption = { "pageLength" : 5,
"pagingType": "simple",
"info": false ,
"searching": false,
"select" : {
style: 'single'
},
"lengthChange": false,
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
};
dataTable = $('#dataTable').DataTable(dataTableOption );`
Thank you for your help in advance!
This discussion has been closed.
Answers
dataTable.row(':eq(0)').select();
(row().select()
).Not with Select's built in selection controls. However, you have two options:
deselect
and if you find no rows are selected(dataTable.rows({selected:true}).any()
), then reselect that row.Allan