ReynierPM
ReynierPM

Reputation: 18660

Clear previous selection only if checkbox is not clicked in jQgrid?

I have a grid setup with multiselect: true because I need to be able to delete more than one row at the same time. On the onSelectRow event I am loading some data based on the ID and displaying it to the end user. So far so good.

This is the example where everything works fine, the data for ID=219109 is being displayed:

enter image description here

Now look at the following example:

enter image description here

In the example above the first row still highlighted and then I clicked a second one. Because of multiselect is enabled I was able to select both at the same time. The onSelectRow event still working properly which means is loading the data for the ID=282006 but visually it could be confusing for the end user.

What I want to do is to reset the previous selected rows and just highlight the last one I have clicked.

For example using the same images:

However this should only happen when I click in any other place than the checkbox.

enter image description here

In the image above if I click on any column rather than the first one (the one having the checkbox) I should be able to clear the grid selection and choose the last one but if I click on the checkbox it does not matter because is the only way to delete more than one at the time.

I have tried the following:

onSelectRow: function () {
    var rowid = $(this).jqGrid('getGridParam', 'selrow');

    $(this).jqGrid("resetSelection");
    $(this).jqGrid("setSelection", rowid);
}

But it's not working since the behavior is not consistent. You can check the demo here.

Any ideas in how to achieve this?

Upvotes: 0

Views: 855

Answers (1)

Oleg
Oleg

Reputation: 221997

It seems to me that you need just add the option

multiboxonly: true

and remove your current onSelectRow code. See https://jsfiddle.net/OlegKi/949pLpfv/3/. If the user clicks multiple times on checkbox the rows will be selected. The click on another part of the row will deselect all previously selected rows and select only the clicked row.

Upvotes: 1

Related Questions