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
close icon

Changing grid editSettings in code

I'm trying to change the editSettings and toobar of a ejs-grid in script and it's not working..

        <ejs-grid id="grdTS" load="grdTS_Load" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true"
                  actionBegin="actionBegin">
            <e-data-manager url="/Officers/TimeSheet?handler=DataSource" updateUrl="/Officers/TimeSheet?handler=UpdateData"
                            insertUrl="/Officers/TimeSheet?handler=InsertData" adaptor="UrlAdaptor"></e-data-manager>
            <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
            <e-grid-columns>

I'm just testing with a change event for a dropdown.  The code does run but nothing happens.  You can still edit the grid and the menu stays the same.

    function monthChange(args) {
        var gridObj = document.getElementById("grdTS").ej2_instances[0]
        gridObj.editSettings.allowEditing = "false"
        gridObj.toobar = "@(new List<string>() { "Add", "Cancel" })"
    }


1 Reply

PS Pavithra Subramaniyam Syncfusion Team March 13, 2019 05:26 AM UTC

Hi Michael, 
 
Greetings from Syncfusion. 
 
You can achieve your requirement by setting the Boolean value to the editSettings.allowEditing property in JavaScript and assigning an array of string value for grid.toolbar property. Please refer to the below code example and documentation link for more information. 
 
[index.cshtml] 
<ejs-button id="disable" content="Disable"></ejs-button> 
 
<ejs-grid id="grdTS" dataSource="ViewBag.data" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true" 
          > 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column> 
        .  .  . 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    document.getElementById('disable').addEventListener('click', function(args) { 
        var gridObj = document.getElementById("grdTS").ej2_instances[0] 
        gridObj.editSettings.allowEditing = false; 
        gridObj.toolbar = ["Add", "Cancel"]; 
    }); 
</script> 
 
 
 
                              https://ej2.syncfusion.com/javascript/documentation/api/grid/#toolbar  
 
Please contact us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon