Variable page lengths for use with grouping?

Variable page lengths for use with grouping?

hftbhftb Posts: 4Questions: 0Answers: 0
edited January 2014 in General
Hi,
I've got a requirement that will need a datatable to have grouped rows together. I'm currently using the rowgrouping plugin, but the issue I'm facing right now is that the page lengths are fixed, and groups may span more than one page. I'm thinking of either changing the paging to use server-side processing, and return a variable number of rows, dependent on the number of groupings, ie. instead of returning just 10 rows, return the number of rows that make up 10 groupings. Other thoughts I've had is to see if there's a way to have base datatables have different page lengths for each page, and hence make the rowgrouping plugin work properly. I don't have any code to show just yet, but I thought I would bounce this question off the forum, and see if anybody had any brilliant ideas.

Thanks in advance!

Rob.

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    The DataTables paging isn't really designed to work in this manner, so there is no easy solution I'm afraid. It might be possible using the API, particularly with the new API and events in 1.10 (the `page` event specifically), but I suspect it wouldn't be hugely trivial...

    It does sound useful though, it will be a little while before I can create anything to do that, as I'm focusing on 1.10 at the moment, but it sounds like a good idea for a blog post in future.

    Allan
  • hftbhftb Posts: 4Questions: 0Answers: 0
    Thanks Allan. I was hoping for a "use this parameter..." option, but I guess I'll have to roll up my sleeves. ;-)
    One question though, if I'm returning arbitrary number of 'detail' rows - possibly greater than the iDisplayLength parameter passed in the request, will this cause issues with datatables rendering all of the rows that are returned?

    Thanks.

    Rob.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    No - DataTables will draw only the current page - regardless of how many rows you return. You will need to alter the length parameter on the fly. There is no public API to do that in 1.9, but 1.10 has a new `page.len()` method. I'm working on releasing 1.10 beta just now.

    Allan
  • hftbhftb Posts: 4Questions: 0Answers: 0
    Allan,
    I took another tack at this issue. Using your "Hidden Rows Example" here: http://datatables.net/release-datatables/examples/api/row_details.html, I decided to experiment with that. I set up a summary table, that datatables is bound to, and I then had another table that is hidden, that has all of the detail rows in it. I hacked some jQuery code together to pull the rows of data from the detail table and insert it as the 'expanded' rows when the '+' button is clicked. This *almost* gets me what I want. One of the issues is that the detail row columns don't line up with the summary row columns, primarily because it seems I need to wrap the detail rows in anther table tag. Now I think I have two ways of fixing this:
    1) Figure out how to insert the detail rows as extra rows underneath the expanded summary row, or
    2) Grab the summary table header row, and insert the width attributes into the columns in the details row table.

    I've put a working example up on jsfiddle here: http://jsfiddle.net/hftb/jjMQD/9/

    If you could have a look, and maybe provide some suggestions, it would be greatly appreciated!

    Thanks!

    Rob.
This discussion has been closed.