Create Index Values for Every ID, Instead of Every Row

Create Index Values for Every ID, Instead of Every Row

hanzhanz Posts: 4Questions: 1Answers: 0
edited June 2020 in Free community support

Link to test case: http://live.datatables.net/jidaloxe/9/edit

Description of problem: I am using the RowsGroup plugin to merge News Type and Visibility cells for rows with the same ID. The ID column will be hidden but it is visible in the test case for the sake of better understanding. Now I want to add an index column with index values for every ID, instead of every row. The index column code I am using is from here.

Current result:

Desired result: Note: This image is edited, and is not manipulated through code.

Thanks
Hanz

This question has an accepted answers - jump to answer

Answers

  • hanzhanz Posts: 4Questions: 1Answers: 0
    edited June 2020

    Update: http://live.datatables.net/ziluwiki/3/edit
    I made some adjustments to the index column creation code. I made it display the same value so I can use RowsGroup to join it later.

    Current problem: Everything displays properly except for the last index. For some reason, it keeps looping through that index. I excluded the row from the "if" loop. If I put an "else", all indexes will be the same value.

    Please help me with this issue.

    Thanks
    Hanz

  • hanzhanz Posts: 4Questions: 1Answers: 0

    Update: http://live.datatables.net/ziluwiki/6/edit
    I replaced the ID column with index values. However, the last index is still the ID value.

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    Answer ✓

    I'm not clear on what you are trying to do but the order.dt search.dt event handler will be called multiple times on initialization as Datatables will perform order and searching when the table is built. One problem is you need to initialize the counter and index variables inside the event so the reset each time the event handler executes.
    http://live.datatables.net/ziluwiki/7/edit

    Not sure if this fixes your problem but hope it gets you closer.

    Kevin

  • hanzhanz Posts: 4Questions: 1Answers: 0

    Solution: http://live.datatables.net/ziluwiki/10/edit

    Issue 1 Solution:
    I did an "else if" to solve the last index issue as it was outside of the if condition.

    Issue 2 Solution:
    The index numbers did not adapt to the rows when search is applied, so I changed the data source from all records to only sorted records displayed.
    New data source: sortedNews = table.rows({ filter: 'applied' }).data();

    Hope this helps anyone who is attempting to do an index column for merged rows! DataTable, please support this as an API in the future!

This discussion has been closed.