Custom separator rows (1.10)

Custom separator rows (1.10)

GerardoGerardo Posts: 66Questions: 0Answers: 0

Have an ajax source with several fields, including a timestamp and an arbitrary (but grouped in the default order) field.

The intent is to have table wide header rows when 1) date changes or 2) arbitrary field changes.

Got it working. Rows are added in drawCallback (is there a better place?), further modified in createdRow (add classes, add colspan, hide columns).

Got an inordinate amount of headers so added a check based on both classes and data value to ensure to add just one header per day/value.

Now, I have 2 issues:

1) Page info shows: "Showing 1 to 11 of 59 entries" (using scroller, so full set). This includes 53 data rows + 6 header rows.

2) After ajax.reload(), same data source, same data.
Page info shows: "Showing 1 to 11 of 53 entries
(filtered from 59 total entries)". The header rows are not shown.
Neither search("") nor columns().search("") helped.

Related: is there any way to add TH rows? Is that advisable?

Thanks,
Gerardo

Replies

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    You note that you are using Scroller - unfortunately that will not work with rows that are being dynamically injected. Scroller has to assume that the number of rows the DataTable contains is correct and that each row is the same height. Otherwise it can't perform its virtual calculations and things will go wrong. You can have scrolling enabled and that will work, but not the Scroller extension.

    Beyond that, I would need a link to a test case showing the issue, as noted in the forum rules.

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    hi Allan, thanks for answering.
    Started using drawCallback following old code (as mentioned here: http://www.datatables.net/forums/discussion/4093/bscrollcollapse-cutom-headers),
    however found a better place to inject these custom rows, as soon as getting the response from server, in json.

    so I have an addHeaderRows called in both xhr_done and after ajax.reload, with the (classes, colspan, hide columns) moved to rowCallback. [Scratch rowCallback, createdRow is the right place].
    Also takes care of the possible duplication issue, as is done.

    And that fixed the reload issue.

    I see what you mean about Scroller (does it use first row height?).
    Need to find a way to apply height to the injected rows to be able to use scroller accurately.

    But my issue is with the injected rows being counted at all.
    Like overriding page.info().recordsTotal with filter information.

    Will prepare a test case with actual data taken off.

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    does it use first row height?

    Actually it uses the second row's height - the first can sometimes have a border on it. If there aren't three or more rows int he table it will construct a test table to make a best effort calculation with.

    But my issue is with the injected rows being counted at all. Like overriding page.info().recordsTotal with filter information.

    Yes - that is the case. Scroller simply will not work with injected rows. There is no way for it to work that way - the calculations will always be wrong.

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    Scroller will have errors in the "showing x to y of z total entries". x and y will be bogus (unless injected rows have same height as others?).
    Can work around that by disabling scroller AND paging.

    But z is also bogus, in a sense (as injected rows are counted). This, no matter on paging or scrolling.
    Is there a way to override this, so page info uses only "data" rows?
    Maybe a page.filter() function, affecting page.info().recordsTotal and page.info.RecordsDisplay, so if the first page has 2 headers, the page info shows "Showing 1 to 8 of z' total entries"?

    Would this also affect scroller too (is scroller a sliding page)?

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    unless injected rows have same height as others?)

    No - Scroller simply will not work correctly at all with any injected rows. Consider for example the case where you need to know the pixel position of row 1000. The rows are 20px in height, so you can simply to 1000*20. If I were to inject a row that Scroller doesn't know about somewhere in those 1000 rows, that calculation would be wrong.

    Therefore the table body can contain nothing but the rows of the table and they must all be the same height.

    Scroller using the paging functions built into DataTables to operate - paging must be enabled (even although the end user doesn't see the paging controls).

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    So paging needs access to real recordsTotal and recordsDisplay (which does happen now btw, injected rows are seen and counted).

    Could page.filter() maintain two new fields in page.info(), say recordsFiltered and RecordsDisplayFiltered (assume no scroller,either just scrolling or just paging)?

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    recordsFiltered and RecordsDisplayFiltered

    I'm not sure what the difference is between them?

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    recordsFiltered = recordsTotal after applying page.filter(),
    recordsDisplayFiltered = records.Display after applying page.filter()

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    I still don't understand I'm afraid.

    DataTables currently uses:

    • recordsTotal - total records, no filtering
    • recordsFiltered - total records with filtering

    What does RecordsDisplayFiltered add? Is that just the number of records on the page? If so, then the number of rows on the page can be found simply from data.length.

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    Sorry for the delay.

    The context is: DataTables has no concept to data rows and header rows, so when injecting header rows, they are treated as data rows for display/filter purposes.

    page.filter() here would define the data rows set.

    But this would be BEFORE applying user filters, so, as shown to the user, the number of rows is the number of data rows, not (data + header) rows.

    Sorry, was not aware of recordsFiltered, would need a different name.

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    DataTables has no concept to data rows and header rows, so when injecting header rows, they are treated as data rows for display/filter purposes.

    That is correct - regardless of processing mode. However I don't see how RecordsDisplayFiltered would address that. Do you want to have two different classifications of rows in the table body? That would be a significant amount of work I think!

    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    Right.

    In principle, so the number of records shown (and filtered) are those of the data set (minus the header set).
    Then, it should not affect displaying the header rows.

    Just for page.info() purposes.

    Say recordsPageFiltered (named aboved recordsFiltered) = data rows = recordsTotal - headers

    Similar for recordsDisplayPageFiltered = data rows displayed (This looks trickier).

    If there is a pageFilter.

    Thanks,
    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    I understand now - thanks for the clarification.

    That isn't something I currently plan to put into DataTables, but I've added it to my future ideas list.

    Regards,
    Allan

  • GerardoGerardo Posts: 66Questions: 0Answers: 0

    I see, thanks.

    I want to take a stab at it, but wondering if can be done in a plugin. Opening a different thread for that.

    Gerardo

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    For anyone else following this this is the new thread.

    Allan

This discussion has been closed.