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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set initial where and initial sort in Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

132937 Sep 28,2017 05:56 PM UTC Oct 2,2017 07:01 AM UTC ASP.NET MVC 4
loading
Tags: Grid
Nicola
Asked On September 28, 2017 05:56 PM UTC

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


Venkatesh Ayothi Raman [Syncfusion]
Replied On 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. 


Nicola
Replied On September 29, 2017 03:48 PM UTC

Great !!

You understood my issue perfectly. 

Thank you very much


Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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. 


Saravanan Arunachalam [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;