jQWidgets Forums

jQuery UI Widgets Forums Grid select/deselect all in checkbox selection mode

This topic contains 12 replies, has 5 voices, and was last updated by  admin 10 years, 10 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author

  • krnacm
    Participant

    Hi guys,

    I noticed a strange behaviour in grid when selection mode is set to checkBox. When I hit the checkbox in the header to select all rows and after that I deselect all with the same checkbox in the header and when I try to get selected rows count after deselectiong I get not correct count (I get count of all rows instead of count 0). When I select only one row then I get count of all rows + one selected row insted on count 1.

    You can try in JSFiddle http://jsfiddle.net/s3bfC/1/.

    I need this functionality to get work correct, because I need to check how much rows are selected and now I don’t get it to work.

    Thanks.

    Kind regards,
    Matej


    Peter Stoev
    Keymaster

    Hi Matej,

    The wrong is the assumption that getselectedrowindexes.length returns the count of selected items. The method and selection work perfectly. If you select the first row, selectedrowindexes[0] will point to 0, when you unselect it, it will point to -1, but the “length” will return 1.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    krnacm
    Participant

    Hi Peter,

    yes you are right, I know that when I unselect it, it will point to -1, but this behaviour is for me a bit strange, I would expect, when I unselect an item it should not be in the returned list of selected indexes, but OK if it is so intended. But how can I get realy selected count of rows? Do I need to go trought the all returned rows and check where they point? Or do you have and property or method that return only selected rows?

    Thanks in advance.

    Kind regards,
    Matej


    krnacm
    Participant

    Any suggestion?

    Thanks.

    Kind regards,
    Matej


    Peter Stoev
    Keymaster

    Hi Matej,

    If you wish, you can loop through the selectedindexes array and check whether there is -1 value or index.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    krnacm
    Participant

    Hi Peter,

    Thanks, will do so if no other better option.

    Thanks.

    Kind regards,
    Matej


    genachka
    Participant

    I encountered same issue and was hoping for a better solution than to loop through. From my view, I don’t agree that the assumption is wrong in expecting that getselectedrowindexes.length returns the count of selected items because it is 0 until something is selected. And if you select and unselect by rows, everything works correctly. Unselecting a row at a time does remove the array item. It only fails when you use the checkbox on the header to unselect that it fails as instead of it removing the array item, it (for whatever reason?) leaves the item but sets the value to -1. If it were to remove the array item just as a manual unselect did, this wouldn’t be an issue and wouldn’t require a loop or other workaround.


    Peter Stoev
    Keymaster

    Hi genachka,

    We cannot offer a better solution.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    genachka
    Participant

    Thanks for your response. I’m sure there’s some internal logic to it, but I still find it strange that the result of the array contents should differ based on how they are selected/unselected (manual vs. checkbox header).

    I’m looping through currently as a solution, but +1 for feature request to add “getselectedrowcount” that would work on both manual select/unselect but also those triggered by checkbox header select all/unselect all.


    wmklaborn
    Participant

    I have to agree with genachka regarding this topic. Selecting/unselecting individual rows adds/removes indexes to the array as well as the selectall which adds all indexes to the array. Only does unselectall displays a different behavior than the manual individual select/unselect functionality. Having to do a loop through to get a proper count in this scenario is counter-intuitive to the functionality that this method should provide for me.

    wmklaborn


    Peter Stoev
    Keymaster

    Hi wmklaborn,

    Thank you for your comments, wmklaborn. However, if you have tried this with jQWidgets 3.5 before writing your post, you would have found that “getselectedrowindexes” length returns 0 after unselect all. Example: http://jsfiddle.net/jqwidgets/1hpt6qwz/

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    wmklaborn
    Participant

    Thanks Peter!
    Our group only just upgraded to 3.4, thus the reason that my issue still existed. Should this fix info be included in the Release notes? As I’m not seeing it there, thus the reason for posting my original question.

    Thanks for all your help!

    wmklaborn


    admin
    Keymaster

    Hi wmklaborn,

    That has never been an issue so there’s no reason for it to be included in release notes. The behavior was correct and there’s a minor change only due to the fact that several users requested for that change.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.