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

How to set maxlength(Restrict type more than 5 charecter) in editing ejs-grid column edit ? (Urgent)

<e-grid-column field="strVehicleTariffName" type="string" editType="TextBox"  validationRules="@(new { required=true})" headerText="Tariff Name" width="232" ></e-grid-column>

                                        <e-grid-column field="tintVehTariffType" type="number" editType="dropdownedit" validationRules="@(new { required=true})" foreignKeyField="tintVehTariffType" foreignKeyValue="strVehTariffType" dataSource="ViewBag.VehTariffTypeList" edit="new {@params = DropDownList }" headerText="Type" width="112"></e-grid-column>
                                        <e-grid-column field="tintVehTariffACNonAC" type="number" editType="dropdownedit" validationRules="@(new { required=true})" foreignKeyField="tintVehTariffACNonAC" foreignKeyValue="strVehTariffACNonAC" dataSource="ViewBag.VehTariffACNonACList" edit="new {@params = DropDownList }" headerText="A/C" width="92"></e-grid-column>

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 4, 2019 06:40 AM

Hi Pradeep, 

Greetings from Syncfusion support. 

We can achieve your requirement “set max length for string type column in Grid for validation”. By using the maxLength property of validationRules in columns API. 

Refer the below code example. 


<ejs-grid id="Grid" dataSource="ViewBag.dataSource"  toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true"> 
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" newRowPosition="Top"></e-grid-editSettings> 
            <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true, number=true})" width="140"></e-grid-column> 
            <e-grid-column field="CustomerID" headerText="Customer Name" validationRules="@(new { required=true, maxLength=5})" width="150"></e-grid-column> 

Thavasianand S 

PR pradeep October 4, 2019 06:53 AM

I already use but i want to restrict user only can enter 5 character only.user can not type more than 5 character in  it.

TS Thavasianand Sankaranarayanan Syncfusion Team October 7, 2019 03:52 AM

Hi Pradeep, 
We suggest you to use the below solution to resolve this problem. Here we have used the actionComplete event to restrict the characters to enter in the input box. Please refer the below code example for more information. 
<ejs-grid id="Grid" allowPaging="true" load="onLoad" actionComplete="ActionComplete" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })">​ 
    function ActionComplete(args) { 
        if (args.requestType == "beginEdit") { 
            var inputElement = document.getElementById(this.element.id + "CustomerID"); 
            inputElement.setAttribute('maxlength', '5'); 
Refer the help documentation. 
Thavasianand S.

PR pradeep October 9, 2019 12:11 AM

Thanks for its working and thanks for fast support

TS Thavasianand Sankaranarayanan Syncfusion Team October 9, 2019 11:11 PM

Hi Pradeep, 
Thanks for your update. 
We are happy that the problem has been resolved at your end. 
Thavasianand S.  

Live Chat Icon For mobile
Up arrow icon