Unselect currently clicked row

1.3k Views Asked by At

So, I am just curious if it is possible to unselect currently clicked row in jQWidgets Grid.

I have tried the following code but seems like it's not working :

    $("#jqxGrid").on("rowclick", function (event) {

         var selectedRowIdx = event.args.rowindex;

         // this part doesn't work
         $("#jqxGrid").jqxGrid('unselectrow', selectedRowIdx);

         // this part doesn't work as well
         $("#jqxGrid").jqxGrid('clearselection');
         $("#jqxGrid").jqxGrid('selectrow', 0);

    });

Here's how I initialized the grid :

    var columns = { .. some init values here };
    $('#jqxGrid').jqxGrid({
        autoheight: true
        , width: '100%'
        , pageable: true
        , altrows: true
        , source: {}
        , columnsresize: false
        , columnsheight: 25
        , autoheight: true
        , autorowheight: true
        , sortable: true
        , editable: true
        , altrows: true
        , selectionmode: 'singlerow'
        , pagermode: "simple"
        , columns: columns
        , ready : function() {
            columnSelection.initialize('#jqxGrid',0,"10",columns);
        }
        , cellhover: function (element, pageX, pageY){
            // hover churvabels here
        }
    });
2

There are 2 best solutions below

0
On BEST ANSWER

alright I was trying to get this to work as well and here's what I came up with after a ton of searching:

$("#jqxGrid").on('rowclick', function (event) { var index = $("#jqxGrid").jqxGrid('getselectedrowindex'); var clickedIndex = event.args.rowindex; if (clickedIndex == index) { setTimeout(function () { $("#jqxGrid").jqxGrid('clearselection'); }, 10); } });

Also when you're creating the source set dataFields to datafields or else it won't work for some reason

0
On

I suppose that you try to unselect a row before it is selected, because a row is selected after you click on it. If you put your code in timeout, it would probably work.