using indexes

using indexes

yonatanyonatan Posts: 5Questions: 1Answers: 0
edited January 2017 in Free community support

It's not clear to me from the documentation how indexes work.

give a table T
CurItem = Table.rows({ selected: true}); //single selection
Then I understand that
CurItemIndex = CurItem[0];

1) Can I assume that the previous item is at CurItemIndex - 1 if CurItemIndex > 0
2) Can I assume that the next item is at CurItemIndex + 1 if CurItemIndex < logTable.rows().indexes().length ?
(as long as all the items are visible)

Or do I need to do this

var TableIndexs = Table.rows().indexes();
if ( CurItem < TableIndexs.length - 1) {
nextItemIndex = TableIndexs(CurItem+1)
}
if (CurItem > 0) {
previtemIndex = TablesIndexes(CurItem-1)
}

Is the last item always given by
TableIndexs(TableIndexs.length - 1)

Thanks

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    1) Can I assume that the previous item is at CurItemIndex - 1 if CurItemIndex > 0

    No. The "data index" is not the same as the "display index". Consider sorted data, the data indexes might be reordered out of sequence to make the current display order.

    What exactly is to you are trying to do?

    Allan

  • yonatanyonatan Posts: 5Questions: 1Answers: 0

    user selects a row
    user press a delete button
    //after delete auto select the next row
    if (there is a next row) { //not last visible in table
    select it
    } else if (there is a previous row) {
    select it
    } else {
    dont select anyyhing
    }

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    To get the current list of indexes you can use:

    table.rows( { order: 'applied' } ).indexes()
    

    Then search for the current row index in that (table.row( { selected: true } ).index()).

    That will tell you where in the indexes array the currently select row is, and thus allow you to do a +1 or -1 on that position to get the next index.

    Allan

This discussion has been closed.