How do you manually sort a Kendo UI Grid in ASP MVC page?

hyprsleepy

I have a grid which is seen below.

I have already made it Sortable as you can see. But when someone clicks search I want the grid sorted by a particular field - the SurveyDueDate.

How do I set the field the grid is sorted by and if it is ascending or descending from the javascript call in the search button click event?

Everything I look at on the grid only shows how to make it Sortable and doesn't say how to explicitly set the sort.

@(Html.Kendo().Grid<SurveyMaintenance.Models.StoreSurveyList>()
    .Name("idGridStoreSurveyList")
    .HtmlAttributes(new { ID = "idGridStoreSurveyList", Class = "k-grid-header" })
    .Columns(columns =>
    {
        columns.Bound(p => p.IsSelected)
            .ClientTemplate("<input type='checkbox' class='StoreSurveyListDeleteItemRequest' #= (IsSelected === true) ? checked='checked' : '' # onclick='StoreSurveyListFunctions.toggleStoreSurveyListDeleteItemRequestSelection(this)' />")
            .HeaderTemplate("<input type=\"checkbox\" id=\"toggleAllStoreSurveyListDeleteItems\"/>")
            .Width(40)
            .Filterable(false)
            .Sortable(false);

        columns.Bound(p => p.SurveyDueDate)
            .Template(@<text></text>)
            .ClientTemplate("#= kendo.toString(SurveyDueDate,'MM/dd/yyyy') #")
            .Width(130);

        columns.Bound(p => p.StoreCompleted)
            .Width(110);

        columns.Bound(p => p.SurveyName);

        columns.Bound(p => p.DeliveryDate)
            .Template(@<text></text>)
            .ClientTemplate("#= kendo.toString(DeliveryDate,'MM/dd/yyyy') #")
            .Width(130);

        columns.Bound(p => p.SupplierName)
            .Width(200);
    })
    .Sortable()
    .Filterable()
    .Navigatable()       
    .Resizable(resize => resize.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(500)
        .ServerOperation(false)
        .Events(events => events.Error("grid_error_handler"))
        .Model(model => { model.Id(p => p.SurveyID); })
        .Read(
           read => read.Action("GetStoreSurveyList", "StoreSurveyList").Data("additionalDataStoreSurveyList")
        )
    )
)
hyprsleepy

I figured it out.

Inside the javascript call I put the following code:

    var kendoGrid = $("#idGridSurveyList").data("kendoGrid");
    var dsSort = [];
    dsSort.push({ field: "DeliveryDate", dir: "desc" });
    kendoGrid.dataSource.sort(dsSort);

There is a sort method for the datasource of a kendo grid and you can pass it an array that holds the field and direction of the sort.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Kendo-UI Grid (w/ MVC Wrappers) : How do I create a button that navigates to details page

From Dev

Kendo MVC UI sort grid using DropDownList

From Dev

How to load manually data in kendo ui grid

From Dev

How to reuse and parameter a Kendo UI grid EditorTemplate (using ASP MVC)?

From Dev

How Do I Synch Kendo UI Grid Datasource On Sort?

From Dev

Kendo UI, How to manually call validate() on kendo grid cell

From Dev

Kendo UI, How to manually call validate() on kendo grid cell

From Dev

Using Kendo MultiSelect with Kendo UI Grid in ASP.NET MVC

From Dev

In Kendo UI MVC Grid how do i add a Kendo Upload to each row?

From Dev

Kendo UI. Reset Grid to first page after sort changed

From Dev

How to resolve issues with CRUD Operations in an ASP.NET MVC Kendo UI Grid

From Dev

How to set default value for any field of a ViewModel using Kendo UI Grid and ASP.NET MVC?

From Dev

How to customize Kendo UI grid delete confirmation dialog using ASP.NET MVC wrappers?

From Dev

Reference to Kendo UI (ASP.NET MVC) dropdown on a grid

From Dev

Auto incrementing column in Kendo UI Grid with ASP.NET MVC

From Dev

Reference to Kendo UI (ASP.NET MVC) dropdown on a grid

From Dev

How do you disable editting on a Kendo Grid in MVC using code behind?

From Dev

Sorting on Kendo UI MVC Grid

From Dev

Sorting on Kendo UI MVC Grid

From Dev

Kendo UI MVC Grid Not Updating

From Dev

How to change the default filter operator in kendo ui grid mvc

From Dev

How to filter a Kendo UI MVC grid using a dropdown list

From Dev

How to transpose rows and columns in a Kendo UI grid in MVC application?

From Dev

How to change the default filter operator in kendo ui grid mvc

From Dev

How to find the specific word in kendo UI grid in MVC

From Dev

How to change the background of a cell dynamically in a Kendo MVC UI Grid?

From Dev

How to change the default value of Grid page size in Kendo UI?

From Dev

How to use Asp.net Kendo ui grid resource

From Dev

How Can I Hide Kendo UI Grid Columns using JavaScript, React, Angular, Vue or ASP.NET MVC

Related Related

  1. 1

    Kendo-UI Grid (w/ MVC Wrappers) : How do I create a button that navigates to details page

  2. 2

    Kendo MVC UI sort grid using DropDownList

  3. 3

    How to load manually data in kendo ui grid

  4. 4

    How to reuse and parameter a Kendo UI grid EditorTemplate (using ASP MVC)?

  5. 5

    How Do I Synch Kendo UI Grid Datasource On Sort?

  6. 6

    Kendo UI, How to manually call validate() on kendo grid cell

  7. 7

    Kendo UI, How to manually call validate() on kendo grid cell

  8. 8

    Using Kendo MultiSelect with Kendo UI Grid in ASP.NET MVC

  9. 9

    In Kendo UI MVC Grid how do i add a Kendo Upload to each row?

  10. 10

    Kendo UI. Reset Grid to first page after sort changed

  11. 11

    How to resolve issues with CRUD Operations in an ASP.NET MVC Kendo UI Grid

  12. 12

    How to set default value for any field of a ViewModel using Kendo UI Grid and ASP.NET MVC?

  13. 13

    How to customize Kendo UI grid delete confirmation dialog using ASP.NET MVC wrappers?

  14. 14

    Reference to Kendo UI (ASP.NET MVC) dropdown on a grid

  15. 15

    Auto incrementing column in Kendo UI Grid with ASP.NET MVC

  16. 16

    Reference to Kendo UI (ASP.NET MVC) dropdown on a grid

  17. 17

    How do you disable editting on a Kendo Grid in MVC using code behind?

  18. 18

    Sorting on Kendo UI MVC Grid

  19. 19

    Sorting on Kendo UI MVC Grid

  20. 20

    Kendo UI MVC Grid Not Updating

  21. 21

    How to change the default filter operator in kendo ui grid mvc

  22. 22

    How to filter a Kendo UI MVC grid using a dropdown list

  23. 23

    How to transpose rows and columns in a Kendo UI grid in MVC application?

  24. 24

    How to change the default filter operator in kendo ui grid mvc

  25. 25

    How to find the specific word in kendo UI grid in MVC

  26. 26

    How to change the background of a cell dynamically in a Kendo MVC UI Grid?

  27. 27

    How to change the default value of Grid page size in Kendo UI?

  28. 28

    How to use Asp.net Kendo ui grid resource

  29. 29

    How Can I Hide Kendo UI Grid Columns using JavaScript, React, Angular, Vue or ASP.NET MVC

HotTag

Archive