Set Checkbox based on length of another field

I want to set a checkbox ("Active") in a grid based on the presence of text (length>0) in another cell ("Description").  I want the grid to update in Batch mode but have the checkbox get set dynamically based on changes to the text.   Can this be done?

Here is my grid:
<ejs-grid id="scaledata" dataSource="ViewBag.AttributeScaleData" dataBound="onScaleDatabound" allowGrouping="true" gridLines="Both" 
          toolbar="@(new List<string>() {"Update","Cancel" })" allowTextWrap="true" allowResizing="true">
     <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="true" mode="Batch"></e-grid-editSettings>
     <e-grid-groupsettings showDropArea="false" columns="@(new string[] {"ScaleType"})" captionTemplate="#captiontemplate"></e-grid-groupsettings>
          <e-grid-columns>
                <e-grid-column field="Id" visible="false" isPrimaryKey="true"></e-grid-column>
                <e-grid-column field="AttributeId" visible="false"></e-grid-column>
                <e-grid-column field="ScaleType" visible="false"></e-grid-column>
                 <e-grid-column field="ScalePosition" headerText="#" headerTextAlign="Center" textAlign="Center" width="30" allowEditing="false"></e-grid-column>
                 <e-grid-column field="Description" headerText="Description" headerTextAlign="Center" ></e-grid-column>
                 <e-grid-column field="Active" visible="true" editType="booleanedit" width="100"></e-grid-column>
          </e-grid-columns>
</ejs-grid>

3 Replies 1 reply marked as answer

PG Praveenkumar Gajendiran Syncfusion Team February 18, 2021 10:06 AM UTC

Hi Bill,

Thanks for contacting Syncfusion support.

Based on your query and provided information, we suspect that your requirement is to dynamically update the checkbox column value based on particular column field value while batch editing. For this we suggest you to use setCellValue method of Grid in the cellSave event of Grid as demonstrated in the below code example to achieve your requirement. 
Code Example :  
<ejs-grid id="Grid" dataSource="ViewBag.dataSource" toolbar="@(new List<string>() { "Update","Cancel" })" allowPaging="true" cellSave="cellSave"> 
    <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="true" mode="Batch"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true, number=true})" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" validationRules="@(new { required=true})" textAlign="Right" editType="numericedit" format="C2" width="120"></e-grid-column> 
        <e-grid-column field="OrderDate" headerText="Order Date" editType="datepickeredit" format="yMd" width="170"></e-grid-column> 
        <e-grid-column field="ShipCountry" headerText="Ship Country" editType="dropdownedit" width="150"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column> 
        <e-grid-column field="Verified" headerText="Verified" displayAsCheckBox="true" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
 
 
<script> 
function cellSave(args) {
        
var grid = document.getElementById("Grid").ej2_instances[0]; //Grid instances 
        if (args.columnName == "CustomerID") {   
// Updates particular cell value by passing primary key value, column field, new value as parameter to the setCellValue method of Grid. 
            if (args.value.length > 0) { 
                grid.setCellValue(args.rowData.OrderID, "Verified", true) 
            } else { 
                grid.setCellValue(args.rowData.OrderID, "Verified", false) 
            } 
        } 
    } 
</script> 

Here we have prepared a sample based on this for your reference,
 
Sample : https://www.syncfusion.com/downloads/support/forum/162693/ze/sample_core-166201608.zip

Please refer the below API document for cellSave event and setCellValue method of Grid

API Link:  https://ej2.syncfusion.com/javascript/documentation/api/grid/#cellsave
                   https://ej2.syncfusion.com/javascript/documentation/api/grid/#setcellvalue

Please get back to us if your need further assistance.

Regards,
Praveenkumar G
 



Marked as answer

BI Bill February 19, 2021 07:27 PM UTC

That did it!
Thank you very much.



PG Praveenkumar Gajendiran Syncfusion Team February 22, 2021 06:05 AM UTC

Hi Bill, 

You are welcome. We are glad that the provided solution helped resolve your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Praveenkumar G 


Loader.
Up arrow icon