Grouping two rows to one record (and sorting)

Grouping two rows to one record (and sorting)

DaniloDanilo Posts: 6Questions: 0Answers: 0
edited October 2009 in General
Hi Allan,

first of all thank you so much for this awesome plugin.

The table I would like to apply DataTables on consists of two-rows-records, i.e. a first row (with a few cols) with actual data and then a second initially hidden row with one cell spanning over the full width (see example code below). That second row contains options for the preceding row - both should always stay together. Via jQuery I toggle the display of the 2nd row when the 1st row is clicked.
Now DataTables of course only shows 5 rows (with 10 set) because it counts the 5 hidden rows as well. And sorting puts the 2nd row "away" from its "partner/parent" row. Furthermore, sorting only works on the first column which I think is due to the 2nd row using colspan.

Now, I would like to know if it is possible to group pairs of rows to one entity, i.e. counting and sorting always applies to the first row of the pair only, and the 2nd row always follows its corresponding 1st row?

I searched quite a bit and read the examples but I can't seem to get this done. Thank you in advance.

[code]
data 1
data 2
data 3
data 4
data 5


options
[/code]

In short, I want DataTables to read this code snippet as one record. Is that applicable?

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Danilo,

    Have a look at this example, which might help: http://datatables.net/examples/api/row_details.html

    Basically, DataTables doesn't really support colspans, so it's going to fall over there, and as you point out the number of rows goes all wonky etc. What you can do however is to put the information in the 'options' row into a 6th and hidden column, and then use the fnOpen() and fnClose() API functions to show/hide the 'options' row.

    Hope that helps,
    Allan
This discussion has been closed.