jQWidgets Forums

jQuery UI Widgets Forums Grid Selected items on re-sort incorrect?

This topic contains 7 replies, has 2 voices, and was last updated by  jonj 12 years, 11 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • Selected items on re-sort incorrect? #5003

    jonj
    Member

    It appears that the selected items (in selectionmode: ‘multiplerows’) are not correctly preserved when applying a new sort. I can provide a video if needed to demonstrate. Is this a known issue?

    Selected items on re-sort incorrect? #5005

    Peter Stoev
    Keymaster

    The selection is per bound items not per visual items. if you select the 3rd row and change the sort order, the selected row may not be the 3rd row anymore after sorting.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Selected items on re-sort incorrect? #5076

    jonj
    Member

    A different piece of data is selected post-sort, regardless of visual order. In other words, if I have item 1, item 2, item 3, item 4, and item 5, and select item 2, when I resort, item 3 might be selected.

    Is that the intended behavior? Do I need to run an update to re-bind the select post-sort?

    Selected items on re-sort incorrect? #5083

    Peter Stoev
    Keymaster

    Hi jonj,

    I think that I am missing something because when I select a row and sort, the selected row is the same row with the same data as it was before the sorting. I am testing the Grid in bound mode. In virtual mode, the selection depends only by the index of the row as the Grid does not know anything about the data in that mode. Could you provide a small sample that reproduces the reported behavior with a Grid that has few records?

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Selected items on re-sort incorrect? #5130

    jonj
    Member

    The scenario is that if you select multiple rows and call

    var selected = $('#jqxGrid').jqxGrid('selectedrowindexes');

    then the reference is correct. But if you resort, and call the same function, the “selected” array does not point to the same rows.

    Selected items on re-sort incorrect? #5131

    jonj
    Member

    BTW, in the midst of getting your input/help, may I thank you for what a wonderful product you have created. Amazing. 🙂

    Selected items on re-sort incorrect? #5135

    Peter Stoev
    Keymaster

    Hi jonj,

    According to me the selected items are correct.

    Here’s my test code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
    <script type="text/javascript" src="../../scripts/gettheme.js"></script>
    <script type="text/javascript" src="generatedata.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var theme = getTheme();
    var source =
    {
    localdata: generatedata(100),
    datatype: "array"
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    $("#jqxgrid").jqxGrid(
    {
    width: 670,
    source: dataAdapter,
    theme: theme,
    sortable: true,
    selectionmode: 'multiplerows',
    columns: [
    { text: 'First Name', dataField: 'firstname', width: 100 },
    { text: 'Last Name', dataField: 'lastname', width: 100 },
    { text: 'Product', dataField: 'productname', width: 180 },
    { text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
    { text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
    { text: 'Total', dataField: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' }
    ]
    });
    $("#Button").click(function () {
    var selected = $('#jqxgrid').jqxGrid('selectedrowindexes');
    $.each(selected, function () {
    alert(this);
    });
    });
    });
    </script>
    </head>
    <body class='default'>
    <input type="button" value="Button" id="Button" />
    <div id="jqxgrid">
    </div>
    </body>
    </html>

    – When I select the visual rows – 2, 5 and 8 and click the Button the result is 1, 4 and 7(the indexation starts from 0).
    – Then I click the ‘First Name’ column’s header to sort the Grid and click the Button again.
    – The result after clicking the button is 1, 4 and 7 as it was the last time.
    – I change the sort column by clicking the Product’s header and click the Button. The result is 1, 4 and 7.
    – I change the sort order of the Product’s column by clicking it again and click the Button. The result is 1, 4 and 7.
    – After clicking the Product’s column again, the sorting is removed and I click the Button. The result is 1, 4, 7.

    – 1, 4 and 7 are bound indexes, not visual indexes. When you change the sort order, the bound indexes are not changed, only the visual order of the rows is changed.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Selected items on re-sort incorrect? #5174

    jonj
    Member

    That was what I was missing. I was using the literal position-based index, not the bound index. Thank you for the clarification.

    My new code:

    var griddata = $('#jqxGrid').jqxGrid('getdatainformation'); // griddata.rowscount = total rows
    var selected = $('#jqxGrid').jqxGrid('selectedrowindexes');
    var rows = [];
    for (var r = 0; r < griddata.rowscount; r++) {
    var row = $('#jqxGrid').jqxGrid('getrenderedrowdata', r);
    for (var s in selected)
    if (row.boundindex == selected[s])
    rows.push(row);
    }

    Thank you!

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

You must be logged in to reply to this topic.