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

Disable/Hide isPrimary column on Dialogue Edit mode

I have been started using SyncFusion controls in ASP.NET Core 2.0 using MVC6 tags. I want to add record from dialogue in Grid. Its achievable but I want that isPrimary column donot show on dialogue. Also, if i donot type isPrimary column value then data not get posted to server side. Please guide me on this.

Code:

       
                     
               
               
               
               
           
       


public ActionResult Insert([FromBody]CRUDModel order)
{
_orderService.Insert(order.Value);
return Json(order);
}
Thanks,
Utkarsh

3 Replies

VN Vignesh Natarajan Syncfusion Team October 23, 2017 01:42 PM UTC

Hi Utkarsh, 
 
Thanks for using Syncfusion products. 
 
Query: “I want that isPrimary column donot show on dialogue. Also, if i donot type isPrimary column value then data not get posted to server side 
 
We suspect that you want to hide/disable the primary key column in Grid. To achieve this, we suggest you to use is-identity property of the column. When we enable is-identity property, primarykey column will be disabled from editing and adding.  
Please refer the below code snippet and screenshot for the output. 
 
<ej-grid id="FlatGrid" allow-paging="true" action-begin="begin" action-complete="complete"> 
    <e-datamanager json="(IEnumerable<object>)ViewBag.datasource" update-url="Home/NormalUpdate" insert-url="Home/NormalInsert" remove-url="Home/NormalDelete" adaptor="remoteSaveAdaptor" /> 
    <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="@(EditMode.Dialog)"></e-edit-settings> 
    <e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() {"add","edit","delete","update","cancel" })"></e-toolbar-settings> 
    <e-columns> 
        <e-column field="OrderID" header-text="Order ID" is-primary-key="true" is-identity="true" validation-rules='new Dictionary<string, object>() { {"required",true}, {"number",true} }' text-align="Right" width="75"></e-column> 
        <e-column field="CustomerID" header-text="Customer ID" validation-rules='new Dictionary<string, object>() { {"required",true}, {"minlength",3} }' width="80"></e-column> 
        <e-column field="EmployeeID" header-text="Employee ID" edit-type="@(EditingType.Dropdown)" text-align="Right" width="75"></e-column> 
      
 
 
 
 
Note: The column which is specified as isIdentity will be in read-only mode both while editing and adding a record.  
Refer the code snippet for auto updating the primaryKey column in server side 
 
public ActionResult DialogInsert([FromBody]CRUDModel<Orders> myObject) 
        { 
            Random ran = new Random(); 
            myObject.Value.OrderID = ran.Next();// For isIdentity column, need to generate a new value while inserting new record.  
            order.Insert(0, myObject.Value); 
            return Json(order); 
        } 
 
 
Refer our online documentation for your reference. 
 
 
If you want to hide the primarykey column, it can be achieved by visible property of the column. Please refer the below code and screenshot 
 
   <e-column field="OrderID" header-text="Order ID" is-primary-key="true" is-identity="true" visible="false" validation-rules='new Dictionary<string, object>() { {"required",true}, {"number",true} }' text-align="Right" width="75"></e-column> 
 
 
 
 
PrimaryKey column will not visible in the Grid, when visible property of the column is set to false.  
 
Refer the API documentation on the visible from below link 
 
 
Regards, 
Vignesh Natarajan 
 



'W 'wale December 28, 2018 10:33 AM UTC

is it possible to disable on edit and then enable on insert ?

i'm trying to do this with .net core and ejs grid


TS Thavasianand Sankaranarayanan Syncfusion Team December 31, 2018 11:05 AM UTC

Hi Utkarsh, 

Query : Want to add record from dialogue in Grid. Its achievable but I want that isPrimary column do not show on dialogue.  
 
The Grid have 3 options to achieve your requirement please find the available options 
 
Disable:  
 
We can able disable the primary key field while adding new record. Grid column model have ‘column.isIdentity’ property. If set it true, then It will disable that particular field while adding a new records. 


Hide : 
 
We can hide the primary column text box by using the css properties. Please find the css class. 

.e-dlg-content .e-insertedrow .e-gridform.e-formvalidator .e-table tbody tr:first-child { 
    display: none; 
} 


Dialog Template 

The grid have an option to customize full the edit dialog. Which help you to add new field on editing and hide the existing field in the grid. Please find the sample  

Sample link: 

UG Documents: 

Please contact us if you need any further assistance. 

Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon