table.rows(rowNumber).data()[0] working not correct
table.rows(rowNumber).data()[0] working not correct
Alexey1987
Posts: 9Questions: 2Answers: 0
I must add class selected in focusing "tr". I set Javascript Datasource like this (http://datatables.net/examples/data_sources/js_array.html)
var a = keys.fnGetCurrentPosition(); // return right selected row index. Example a:[1, 3]
var rowNumber = a[1]; // row 3 is current position in table(right info).
var tr = table.rows(rowNumber).nodes() // this function return not correct row index 35
.to$() // Convert to a jQuery object
.toggleClass('selected');
var selectedId = table.rows(rowNumber).data()[0];
Help me please!!!
This discussion has been closed.
Answers
If you want to trigger an action when a cell is in focus, use the key-focus event of KeyTables. This provides a hook into the cell.
Check this page.
http://datatables.net/reference/event/key-focus
The
fnGetCurrentPosition
method is from a legacy version of KeyTables that is no longer supported. I'd suggest updating to v2 as the first step.Allan
Allan: I have version 1.10.4. What are method you suggest?
Allan means you should update KeyTables.
https://datatables.net/download/packages
I get rowindex and resolve my issue with next code string keys.fnGetCurrentTD().parentElement._DT_RowIndex
function rowSelect(event) {
if ((event.which == 32) && (event.ctrlKey)) {
var rowNumber = keys.fnGetCurrentTD().parentElement._DT_RowIndex;
var tr = table.rows(rowNumber).nodes()
.to$() // Convert to a jQuery object
.toggleClass('selected');
var selectedId = table.rows(rowNumber).data()[0][0];
event.preventDefault();
}
}
Thanks for all!
That is a private property that I would not suggest you use. Like all private properties, it can and will change between versions.
Allan
Allan. What a function i can use?
It looks like KeyTable 2 doesn't actually have a method to get the currently focused cell - I'll fix that shortly. At the moment you need to use
key-focus
to know what cell is focused.Allan
My issue is reterned, when I updated from 1.10.4 to 1.10.9 Datatable version. I can't using key-focus, because I must move on table with hot-keys(KeyTables) and when pressed 'ctrl+space' focused row must be selected. I want get current focused row position via key, because I use hot keys and not button click. Help me please!
I've committed a new selector option that will be released in KeyTable 1.1 which lets you do:
table.cell( { focused: true } );
to get the focused cell. That change is in the nightly version if you want to try it.Allan