简体   繁体   中英

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:

在此处输入图片说明

Now look at the following example:

在此处输入图片说明

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:

  • Load a fresh grid with no rows selected
  • Click on ID=219109 : highlight and select this row
  • Click on ID=282006 : clear the grid and highlight this row

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

在此处输入图片说明

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM