Creating entities with value-type read only columns

I have entities where some columns are just for display.  My fields are typically (non-nullable) value types.  The problem is during entity creation (using the CreateUrl, as the fields are read only they end without a value (even the value default), which cause problems during model binding.  Is there a way to specify a default value for a grid column during the creation process in the ASP.NET Core grid or do I have to create an input model that has a nullable type for these column?

1 Reply

HJ Hariharan J V Syncfusion Team September 7, 2018 11:43 AM UTC

Hi Sellinger, 
 
Thanks for contacting Syncfusion support. 
 
Yes we can set column default value by following ways: 
 
  1. You can set the default value directly  by using ‘defaultValue’ in your grid column definition. Please find the code example
 
   
<ejs-grid id="Grid" actionBegin="actionBegin" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"  allowPaging="true"> 
    <e-data-manager url="/Home/UrlDatasource/" insertUrl="/Home/Insert" removeUrl="/Home/Delete" updateUrl="/Home/Update" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager> 
    <e-grid-editsettings allowEditing="true" allowAdding="true" allowDeleting="true"></e-grid-editsettings> 
   
    <e-grid-columns> 
         
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer Name"  width="150"></e-grid-column> 
        <e-grid-column field="Freight" editType="numericedit" headerText="Freight" format="C2" width="120"></e-grid-column> 
        <e-grid-column field="ShipCountry" headerText="Ship Country" defaultValue="USA" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
 
  1. You can the default value by using ‘actionBegin’ event with its request as ‘save’. Please find the code example.
 
        
 
<ejs-grid id="Grid" actionBegin="actionBegin" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"  allowPaging="true"> 
    <e-data-manager url="/Home/UrlDatasource/" insertUrl="/Home/Insert" removeUrl="/Home/Delete" updateUrl="/Home/Update" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager> 
    <e-grid-editsettings allowEditing="true" allowAdding="true" allowDeleting="true"></e-grid-editsettings> 
   
    <e-grid-columns> 
         
    . . . 
        <e-grid-column field="ShipCountry" headerText="Ship Country" defaultValue="USA" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    function actionBegin(args) {   
        if (args.requestType == "save" && args.data['CustomerID'] == '') { 
            args.data['CustomerID'] = 'VINET';   // set the  column value while running time             
        } 
    } 
</script> 
 
 
 
Please find the sample for your reference. 
 
 
Documentation : 
 
 
Regards, 
Hariharan 


Loader.
Up arrow icon