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

EjsGrid use different model on CRUD operations

Hello,

I'm wondering if is it possible to use different model on CRUD operations?

My current situation:
I'm using grid to display vehicle statistic and I using  statistics model, but performing CRUD operations I need to use different model, because I need to have different data about vehicle.

Right now all I able to achieve is use different Url's as you can see below:
<EjsGrid AllowPaging="true" AllowSorting="true" AllowSelection="true" TValue="VehicleListModel" Toolbar="@(new List<string>() { "Search", "Add", "Edit", "Delete" })">
    <EjsDataManager Url="https://localhost:25012/api/VehicleStats" CrudUrl="https://localhost:25012/api/Vehicle" CrossDomain="true" Adaptor="Adaptors.ODataV4Adaptor" Offline="true"></EjsDataManager>
    <GridSearchSettings Fields="@(new string[] { "Number" })" Operator="@Operator.Contains" IgnoreCase="true"></GridSearchSettings>
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog" ShowDeleteConfirmDialog="true"></GridEditSettings>
    <GridPageSettings PageCount="5"></GridPageSettings>
    <GridColumns>
        <GridColumn Field="@nameof(VehicleListModel.Id)" HeaderText="ID" IsPrimaryKey="true" TextAlign="@TextAlign.Left"></GridColumn>
        <GridColumn Field="@nameof(VehicleListModel.Number)" HeaderText="Name" TextAlign="@TextAlign.Justify"></GridColumn>
        <GridColumn Field="@nameof(VehicleListModel.FilesCount)" HeaderText="Files" TextAlign="@TextAlign.Center"></GridColumn>
        <GridColumn Field="@nameof(VehicleListModel.ActiveScheduleCount)" HeaderText="Schedules" TextAlign="@TextAlign.Right"></GridColumn>
    </GridColumns>
</EjsGrid>

1 Reply

VN Vignesh Natarajan Syncfusion Team January 15, 2020 03:43 AM UTC

Hi Laimis,  
 
Greetings from Syncfusion support.  
 
Query: “but performing CRUD operations I need to use different model, because I need to have different data about vehicle. 
 
Yes, you can use different model class in the WebAPI service, but that alternate model must have properties similar to model class define in Grid data. Because while performing CRUD operations we will send the PUT, POST, DELETE request along the with modified data (as object) to server. Based on the model class defined in the server, data will be serialized if your alternate model class has similar properties. 
 
But in your code example, you have used Offline property of EjsDataManager as true. While enabling that property all the Grid actions like filtering, sorting, CRUD will take place locally. No request will be sent to server for data operations. Because Offline property is used to bind the remote data locally to Grid.  
 
Kindly get back to us if you have further queries.  
  
Regards, 
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon