table.rows(rowNumber).data()[0] working not correct

table.rows(rowNumber).data()[0] working not correct

Alexey1987Alexey1987 Posts: 9Questions: 2Answers: 0
edited September 2015 in Free community support

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!!!

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    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

  • allanallan Posts: 63,754Questions: 1Answers: 10,509 Site admin

    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

  • Alexey1987Alexey1987 Posts: 9Questions: 2Answers: 0

    Allan: I have version 1.10.4. What are method you suggest?

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Allan means you should update KeyTables.

    https://datatables.net/download/packages

  • Alexey1987Alexey1987 Posts: 9Questions: 2Answers: 0
    edited September 2015

    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!

  • allanallan Posts: 63,754Questions: 1Answers: 10,509 Site admin

    That is a private property that I would not suggest you use. Like all private properties, it can and will change between versions.

    Allan

  • Alexey1987Alexey1987 Posts: 9Questions: 2Answers: 0

    Allan. What a function i can use?

  • allanallan Posts: 63,754Questions: 1Answers: 10,509 Site admin

    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

  • Alexey1987Alexey1987 Posts: 9Questions: 2Answers: 0

    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!

  • allanallan Posts: 63,754Questions: 1Answers: 10,509 Site admin

    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

This discussion has been closed.