This is a migrated thread and some comments may be shown as answers.

Selected item style stay when calling set_selected(false)

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc-André
Top achievements
Rank 1
Marc-André asked on 25 Jul 2013, 05:52 PM
Hi!

We are using a RadGrid to display some elements... In the "ClientSettings" section, we added "<ClientEvents OnRowClick="rowClick" />" to call a JS function when a row is clicked...

In that function, we have some code that checks if the row that the user just clicked was already selected. If it was, it calls the method "set_selected(false)" on the selected element and disable buttons.

This is working perfectly with IE8... But won't work in Chrome, Firefox, or IE10... In those browser, the element is actually unselected, but the selected style stays. So the row looks like it's still selected. I also tried to call "clearSelectedItems()" on the radgrid and i have the same problem... Any workaround / plans to resolve this problem?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jul 2013, 07:15 AM
Hi,

I guess you are setting some styles on the selected row,and that's not removed on row deselect.Please have a look at the sample code that i have tried,i have set a CSS for the selected item and on deselect  its removed.If this doesn't help,please provide your full code.

ASPX:
<ClientSettings>
    <Selecting AllowRowSelect="true" />
    <ClientEvents OnRowSelected="RowClick" />
</ClientSettings>

JS:
<script type="text/javascript">
    function RowClick(sender, eventArgs) {
        var grid = sender;
        var MasterTable = grid.get_masterTableView();
        var length = MasterTable.get_selectedItems().length;
        var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
        if (row._selected) {
            alert("Selected");
            row._selected = true;         
            for (var i = 0; i < length; i++) {
                alert("Deselected");             
                MasterTable.deselectItem(MasterTable.get_selectedItems()[i].get_element());
            }
        }
    }
</script>

CSS:
<style type="text/css">
 .RadGrid_Default .rgSelectedRow td
    {
       color: red;
    }
</style>

Thanks,
Shinu
0
Marc-André
Top achievements
Rank 1
answered on 26 Jul 2013, 06:28 PM
Got it!

Since the selection is limited to 1 row, we were only deselecting the first selectedIndex (at index 0)...

It looks like if the user click on row X a first time... then few seconds later click a second time on the same line, get_selectedItems() will return two items (2x the same) insted of just one... Using a "for" statement to deselect all items worked...

Thanks!
Tags
Grid
Asked by
Marc-André
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Marc-André
Top achievements
Rank 1
Share this question
or