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 initial where and initial sort in Grid

Hi,
I have this grid

            @(Html.EJ().Grid<AfroditeProPortal.ViewModels.lista_dettaglio_promozioni>("Grid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource))
            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

.ToolbarSettings(tool => tool.ShowToolbar().ToolbarItems(tbItem =>
{
    tbItem.AddTool(ToolBarItems.Add);
    tbItem.AddTool(ToolBarItems.Edit);
    tbItem.AddTool(ToolBarItems.Delete);
    tbItem.AddTool(ToolBarItems.Update);
    tbItem.AddTool(ToolBarItems.Cancel);

}))
    .Locale("it-IT")
    .AllowSorting()
    .AllowPaging()
    .AllowSelection()
    .PageSettings(page => page.PageSize(14))
    .IsResponsive(true)
    .EnableResponsiveRow(true)
    .MinWidth(400)
    .EditSettings(edit =>
    {
        edit.AllowAdding().AllowDeleting().AllowEditing().AllowEditOnDblClick(false);
    })
    .Columns(col =>
    {
      
        col.Field(c => c.descrizione).HeaderText("Descrizione").TextAlign(TextAlign.Left).AllowEditing(false).Width("50%").Add();
         col.Field(c => c.tipoArticolo).HeaderText("Tipo articolo").TextAlign(TextAlign.Left).AllowEditing(false).Add();
        col.Field(c => c.sconto).HeaderText("Sconto %").Width("10%").Format("{0:N2}").ValidationRules(v => v.AddRule("required", true).AddRule("number",true)).Add();

    })
    .ClientSideEvents(eve =>
    {

        eve.ActionBegin("GridActionBegin");
        eve.RecordDoubleClick("GridRecordDoubleClick");
        eve.RowSelected("GridRowSelected");
        eve.QueryCellInfo("querycellinfo"); 
        eve.Create("GridCreate");
        eve.Load("GridLoad");

    })

I want filter it in the first load
function GridLoad(args)
  {
      var gridDetailObj= $("#Grid").data("ejGrid");
      gridDetailObj.commonQuery.queries = []; //cancella la query attuale e imposta la nuova 
      gridDetailObj.commonQuery.where("tipoArticolo"'equal',"TtipoServizio");
  
  } 

but this not works,  "commonQuery" is undefined

I tried in GridActionBegin also, but not works


if I use a buttons , after load, this works 

@(Html.EJ().GroupButton("filtroDettaglio").Width("100%").Height("100%").GroupButtonMode(GroupButtonMode.RadioButton)
           .ShowRoundedCorner(true)
           .Size(ButtonSize.Mini)
           .Items(item => { item.Add().Text("Servizi"); item.Add().Text("Prodotti"); })
           .SelectedItemIndex(new List<int> { 0 }).ClientSideEvents(eve => eve.Select("filtraDettaglio")))
function filtraDettaglio(args)
        {
            $('#tipoArticolo').val(args.index==0?"TtipoServizio":"TtipoProdotto");
 
            var gridDetailObj= $("#Grid").data("ejGrid");
            gridDetailObj.commonQuery.queries = []; //cancella la query attuale e imposta la nuova              gridDetailObj.commonQuery.where("tipoArticolo"'equal', args.index==0?"TtipoServizio":"TtipoProdotto");             refreshGrid();         }

How can set inital where ?

And i can set initial sort ?

Thanks


4 Replies

VA Venkatesh Ayothi Raman Syncfusion Team September 29, 2017 03:09 PM UTC

Hi Nicola, 

Thanks for contacting Syncfusion support. 

We have achieved your requirement using query and sortSettings property in Grid. In that property, we can give sorting and filtering operation on initial Grid rendering. Please refer to the following code example and Help documentation for more information, 


Code example:  
@(Html.EJ().Grid<SyncfusionMvcApplication9.OrdersView>("FlatGrid") 
                        .Datasource((IEnumerable<object>)ViewBag.datasource) 
                        .AllowFiltering() 
                        .AllowSorting() 
                        .Query("new ej.Query().where('OrderID', 'lessThan', 10252, false)") 
                         .SortSettings(sort => sort.SortedColumns(col => col.Field("EmployeeID").Direction(SortOrder.Descending).Add())) 
                      .FilterSettings(filter => 
                      { 
                          filter.FilterType(FilterType.Menu); 
                      }) 
 
 
         .Columns(col => 
         { 
             . . . 
 
         }) 
 
        .ClientSideEvents(eve=>eve.TemplateRefresh("TR").QueryCellInfo("QueryCellInfo")) 
        ) 


If we misunderstood your requirement, then could you please provide more information about your requirement? 

Regards 
Venkatesh Ayothiraman. 



NI Nicola September 29, 2017 03:48 PM UTC

Great !!

You understood my issue perfectly. 

Thank you very much



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 2, 2017 07:00 AM UTC

Hi Nicola,  
  
Thanks for the update. We are happy to hear that your issue has been resolved.  
  
Regards,  
Seeni Sakthi Kumar S. 



SA Saravanan Arunachalam Syncfusion Team October 2, 2017 07:01 AM UTC

Hi Nicola,  
Thanks for your update.            
We are happy that the provided information helped you. 
Regards, 
Saravanan A. 


Loader.
Up arrow icon