Sorting by selected rows when using checkboxes for selection and deferRender

Sorting by selected rows when using checkboxes for selection and deferRender

tom99tom99 Posts: 48Questions: 10Answers: 0

Hi all,

I have a table where the user can select rows with a checkbox column.

Then, I also want to be able to sort by selected rows.

This works OK using dom for sorting, but not with deferRender=true, because not all rows are rendered then.

A solution/hint for this problem would be greatly appreciated.

Example: http://jsfiddle.net/ymscp7f9/

Thanks!

Regards,
Thomas

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @tom99 ,

    To be clear, if I select say the first 5 rows (0-4), what would sorting by those selected rows look like? Or, perhaps, if I selected rows 5-9, and sorted by them? Would you expect them to be at the top, then the other rows below? If so, that's not possible I'm afraid, as the sorting treats all rows the same, selected or otherwise,

    Cheers,

    Colin

  • tom99tom99 Posts: 48Questions: 10Answers: 0
    edited July 2018

    Hi Colin,

    yes, that was the intention. The selected rows should be either at the top or at the bottom, depending on asc/desc sorting.

    I have found some workaround, don't know if this is "too hacky": http://jsfiddle.net/4dnrqhc7/1/

    Essentially, I add a virtual property "selected" to the data, setting it to true or false in the event of a selection or deselection of a row.

    Then I define a function for render/sort for column 0, that is using this virtual property for sort and '' for all other types (don't want to see "true" or "false" in the UI).

    It would have been nicer to be able to use a sort plugin, but those get only 2 values to compare. But I would have needed the possibility to access the API to get the selected rows and then return for example a sorted array of row indexes.

    Regards,
    Thomas

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @tom99 ,

    Another option perhaps would be for the select/deselect to set/unset a flag in a hidden column. You could then use orderFixed to sort first on that column, and then when the user sorts on columns, those sorts would be added to the fixed, hidden sort. I could take a stab at knocking out a prototype for that, if it's a direction of interest.

    Cheers,

    Colin

  • tom99tom99 Posts: 48Questions: 10Answers: 0

    Hi Colin,

    thanks. The idea is that the user has control over what the sorting columns should be. Sorting by selected should be optional and only be done if the user decides to do it.

    Regards,
    Thomas

  • tom99tom99 Posts: 48Questions: 10Answers: 0

    For future reference: I had a bug in my jsfiddle solution in the select/deselect callback handler.

    This is the fixed version: http://jsfiddle.net/4dnrqhc7/3/

This discussion has been closed.