We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamically set and unset column type checkbox

Hi,

i have a grid with single row selection.
On a button i dynamically show a column (<ej:Column Width="50" Visible="false"></ej:Column>)
and set it's type property to checkbox

var obj = $("#GridMaster").ejGrid("instance");
    obj.model.columns[1].type = "checkbox"
    obj.model.columns[1].visible = true;
    obj.refreshTemplate();

It all works well and i can then select multiple rows via checkbox column.
But when i try to revert back to single selection however i cannot select any rows because the grid still waits for rows to be selected by checkbox column which is now hidden and it's type is null as it was when the grid was first created.
This is the code:
 if (obj.model.columns[1].type == "checkbox") {
        obj.model.columns[1].type = null;
        obj.model.columns[1].visible = false;
        obj.model.selectionType = "single"
        obj.model.enableAutoSaveOnSelectionChange = true;
        obj.model.selectionSettings.enableToggle = false;
        obj.refreshTemplate();
};

How to achieve this to work?


1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team December 16, 2016 02:42 PM UTC

Hi Semper, 

Thanks for contacting Syncfusion support. 

We went through the code example that you have shared for us and found that missed to disable the property of _enableCheckSelect in Grid. We have enabled the property when we enabling the checkbox column. So we suggest you to disable that property like as follows, 
Code example
<script> 
        $("#show").click(function () { 
             
            var gridObj = $(".e-grid").ejGrid('instance'); 
 
            gridObj.model.columns[0].type = "checkbox"; 
            
            gridObj.model.columns[0].visible = true; 
            
            gridObj.refreshContent(true); 
        }) 
 
        $("#hide").click(function () { 
 
            var gridObj = $(".e-grid").ejGrid('instance'); 
 
            gridObj.model.columns[0].type = null; 
            gridObj.model.columns[0].visible = false; 
            gridObj.model.selectionType = "single"; 
            gridObj._enableCheckSelect = false; // disable the checkbox property in Grid 
            gridObj.refreshContent(true); 
        }) 
    </script> 

Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon