Hi,
I am using IgniteUi & Asp.net MVC.
I have an igGrid which has checkbox column. I want to allow the user to check only one checkbox in all the rows at any given time.
If the user checks one checkbox, the already checked checkbox should be unchecked. Basically I want the functionality like that of radio button which allows only one item to be checked at any given time. Is there a way to do that through IgniteUi's helper methods or do I have to do it manually through jQuery? Also the checkboxes in iggrid are rendered in span tags instead of input tags which is also going to be a problem for me if I do it manually.
Hello Imran,
Configuring a bool column in igGrid to function similarly to a radio button column may be achieved by manually subscribing a click handler to the grid's checkbox elements (which are rendered as spans). For instance:
$("#grid").on("click", ".ui-state-default", function () { var rowId = $($(this).parents("tr")).attr("data-id"); var rows = $("#grid").igGrid("allRows"); $.each(rows,function (index, value) { var iteratedRowId = $(this).attr("data-id"); if (iteratedRowId != rowId) { if ($("#grid").igGrid("getCellValue", iteratedRowId, "BoolCol") == true) { $("#grid").igGridUpdating("setCellValue", iteratedRowId, "BoolCol", false); } } }); })
$("#grid").on("click", ".ui-state-default", function () {
var rowId = $($(this).parents("tr")).attr("data-id");
var rows = $("#grid").igGrid("allRows");
$.each(rows,function (index, value) {
var iteratedRowId = $(this).attr("data-id");
if (iteratedRowId != rowId) {
if ($("#grid").igGrid("getCellValue", iteratedRowId, "BoolCol") == true) {
$("#grid").igGridUpdating("setCellValue", iteratedRowId, "BoolCol", false);
}
});
})
Hope this helps. Attached is also my test sample for your reference.
Works perfectly. Thanks alot.