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

Two simple questions about the Grid declaration in Razor

I just have a couple of questions regarding the grid declaration in Razor.

Consider this piece of code:

@(Html.EJ().Grid<EmployeeView>("CustomGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource1) 
        .AllowPaging() 
        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.ExternalFormTemplate).ExternalFormTemplateID("#template"); }) 

1. What is "EmployeeView"?
2. Do I need to provide a datasource, considering that the grid would be empty when the page renders and I am the one who are going to fill it with data?

Thank you!!!

PD: This is a follow up from this thread.

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team August 2, 2017 04:58 PM UTC

Hi Samuel, 

Thanks for contacting Syncfusion Support. 

Query #1 :- What is “EmployeeView” ? 

You can create the view-model class  like “EmployeeView” or “OrdersView”  as a type of EJ() and bind to the Grid.  EmployeeView is the model class that we have bind to the Grid. 



Query #2 :- Do I need to provide a datasource, considering that the grid would be empty when the page renders and I am the one who are going to fill it with data? 
 
Initially we have rendered the Grid with empty dataSource and update the Grid dynamically by using “dataSource” method of the Grid. Please refer to the code example:- 

<button id="btn" onclick="myfunction()">Datasource</button> <br /> 
 
@(Html.EJ().Grid<object>("FlatGrid") 
            .AllowPaging() 
             .Columns(col => 
            { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(100).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add(); 
              .   .    . 
            
        }) 
   ) 
 
<script type="text/javascript"> 
        function myfunction() { 
            var grid = $("#FlatGrid").ejGrid("instance"); 
            var dataManager = ej.DataManager("http://mvc.syncfusion.com/Services/Northwnd.svc/Orders"); 
            grid.dataSource(dataManager); 
 
        } 
    </script> 
      

Please refer to the documentation link :- 



Regards, 

Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon