Kendo UI grid binds twice


Trevor Goode

Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out.

Here is the grid code:

@(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>()
    .Name("EventGrid")
    .Columns(columns =>
    {
        columns.Command(command =>
        {
            command.Edit(); command.Destroy(); command.Custom("Copy and Create").Click("copyNAddEvent")
                        .HtmlAttributes(new {@class = "copynadd"}); 
        }).Width(169).Title("Action");
        columns.Bound(e => e.id).Hidden();
        columns.Bound(e => e.contactName).Width(180).Title("Contact Name");
        columns.Bound(e => e.contactEmail).Width(180).Title("Contact Email");
        columns.Bound(e => e.contactPhone).Width(180).Title("Contact Phone #");
    })


    .HtmlAttributes(new { style = "height:500px;" })
    .ToolBar(tools => { tools.Excel(); })
    .Excel(excel => excel
        .AllPages(true)
        .FileName("FlexData.xlsx")
        .Filterable(true)
        .ProxyURL(Url.Action("Excel_Export_Save", "Home"))
    ).Events(x => x.ExcelExport("onExcelExport"))

    .DataSource(datasource => datasource
            .Ajax()
            .ServerOperation(false)
            .Model(model => {
                model.Id(p => p.id);
                model.Field(p => p.application).Editable(false);
                model.Field(p => p.componentType).Editable(false);
                model.Field(p => p.creditedOrSupportEquipment).Editable(false);
                model.Field(p => p.driverType).Editable(false);
                model.Field(p => p.eventName).Editable(false);
                model.Field(p => p.PMinterval).Editable(false);
                model.Field(p => p.PMName).Editable(false);
                model.Field(p => p.scheduledMaintenance).Editable(false);
                model.Field(p => p.equipmentOperatingHours).Editable(false);
                model.Field(p => p.companyName).Editable(false);
                model.Field(p => p.plantName).Editable(false);
                model.Field(p => p.supportingEventDocument).Editable(false);
            })
            .Read(read => read.Action("SearchEvents", "Home").Data("FillSearchParms"))
            .Update(update => update.Action("UpdateEvent", "Home").Data("FillUpdateParms"))
            .Destroy(update => update.Action("DeleteEvent", "Home"))
            .PageSize(10)
            .Events(e => 
            { 
                e.RequestEnd("onRequestEnd");
            })
    )
)

Here is my jQuery for the search button:

$("#SearchBtn").click(function (e) {
    e.preventDefault();

    if (!validator.validate()) {
        return;
    }

    var descr = $("#Description").data("kendoEditor");
    //debugger;

    $.ajax({
        type: "POST",
        url: "/Home/SearchEvents",
        datatype: "json",
        data: {
            id: null,
            eventDate: $("#EventDate").val(),
            eventDateTo: $("#EventDateTo").val(),
            application: defaultDD("Application"),
            componentType: defaultDD("ComponentType"),
            creditedOrSupportEquipment: defaultDD("CreditedOrSupportEquipment"),
            equipmentID: $("#EquipmentId").val(),
            driverType: defaultDD("DriverType"),
            eventName: defaultDD("EventName"),
            make: $("#Make").val(),
            model: $("#Model").val(),
            PMinterval: defaultDD("PMInterval"),
            PMName: defaultDD("PMName"),
            scheduledMaintenance: defaultDD("ScheduledMaintenance"),
            equipmentOperatingHours: defaultDD("equipmentOperatingHours"),
            companyName: defaultDD("CompanyName"),
            plantName: defaultDD("PlantName"),
        },
        success: function (result) {
            $("#searchEventGrid").attr("style", "display: block;");
            //debugger;
            var grid = $("#EventGrid").data("kendoGrid");

            grid.dataSource.read();
            grid.refresh();
            e.preventDefault();

            $("#searchbar").data("kendoPanelBar").collapse($("li.k-state-active"));
        },
        error: function (xhr, txt) {
            //debugger;
            var err = xhr.responseText.match(/.*<body.*>([\s\S]*)<\/body>.*/); ;
            custom_alert(err, "Error!");
        }
    })
})

When I click the search button, it brings back the correct recordset the first time, then refreshes and brings back the entire dataset. For a kendo newbie, can't figure out where the second call is coming from.

Rahul Singh

The problem with your code is that when the button is clicked you are making an ajax call to the server to get the data back and call. grid.dataSource.read();Note that this will make another call to the server and load the data. That's why you feel the grid is bound twice.

Actually, there is no need for an explicit ajax call, since you specified it datasource => datasource.Ajax()in the config, and Kendo already does it . All you need to do is define a function (I hope you have done) that will set your search parameters:-

function FillSearchParms(){
    return{
       id: null,
       eventDate: $("#EventDate").val(),
       eventDateTo: $("#EventDateTo").val(),
       ....and so on
    };
}

Finally, in the button click handler, simply call the read method to load the grid based on the search parameters:

$("#SearchBtn").click(function (e) {
     var grid = $("#EventGrid").data("kendoGrid");
     grid.dataSource.read();
});

Also, note that there is no need to call the refresh method anymore.

Related


Kendo UI grid binds twice

Trevor Goode Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out. Here is the grid code: @(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>() .Name("EventGrid") .Column

Kendo UI grid binds twice

Trevor Goode Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out. Here is the grid code: @(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>() .Name("EventGrid") .Column

Kendo UI grid binds twice

Trevor Goode Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out. Here is the grid code: @(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>() .Name("EventGrid") .Column

Kendo UI grid binds twice

Trevor Goode Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out. Here is the grid code: @(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>() .Name("EventGrid") .Column

Kendo UI grid binds twice

Trevor Goode Inherited a Kendo app I'm trying to fix and really stuck here. I have a search page bound to a datasource twice and can't figure it out. Here is the grid code: @(Html.Kendo().Grid<Flex.Models.AddEntryEditModel>() .Name("EventGrid") .Column

Kendo UI grid update

username I'm using a Kendo UI grid with a service that requires a POST request to update the row as a JSON string instead of a URL encoded form. My grid datasource configuration looks like this: dataSource: new kendo.data.DataSource({ transport: {

Kendo UI grid update

username I'm using a Kendo UI grid with a service that requires a POST request to update the row as a JSON string instead of a URL encoded form. My grid datasource configuration looks like this: dataSource: new kendo.data.DataSource({ transport: {

Kendo UI Grid Hierarchy

Ivan Crojach Karačić What I have is the following DTO passed from the service class ServiceDto { public string Name { get; set; } public string Complete { get; set; } public string Incomplete{ get; set; } public List<ServiceDto> Detail{ get

Kendo UI Grid Hierarchy

Ivan Crojach Karačić What I have is the following DTO passed from the service class ServiceDto { public string Name { get; set; } public string Complete { get; set; } public string Incomplete{ get; set; } public List<ServiceDto> Detail{ get

Kendo UI grid update

username I'm using a Kendo UI grid with a service that requires a POST request to update the row as a JSON string instead of a URL encoded form. My grid datasource configuration looks like this: dataSource: new kendo.data.DataSource({ transport: {

Kendo UI - Tooltips in Grid

no time I am trying to create a tooltip for my grid like this: $("#grid").kendoTooltip({ autoHide: true, showOn: "mouseenter", width:125, height:125, position: "right", filter: ".k-grid-content a.hasTooltip", content: kendo.template

UI unresponsive to Kendo grid

Charvari I've been having issues with kendo grids for the following situations. I have a kendo grid with 18 columns. The user can select multiple rows. The number of rows is mostly over 10000. To get the selected row, I am using grid.select(). To extract conte

Kendo UI grid update

username I'm using a Kendo UI grid with a service that requires a POST request to update the row as a JSON string instead of a URL encoded form. My grid datasource configuration looks like this: dataSource: new kendo.data.DataSource({ transport: {

Kendo UI Grid Hierarchy

Ivan Crojach Karačić What I have is the following DTO passed from the service class ServiceDto { public string Name { get; set; } public string Complete { get; set; } public string Incomplete{ get; set; } public List<ServiceDto> Detail{ get

Kendo UI - Tooltips in Grid

no time I am trying to create a tooltip for my grid like this: $("#grid").kendoTooltip({ autoHide: true, showOn: "mouseenter", width:125, height:125, position: "right", filter: ".k-grid-content a.hasTooltip", content: kendo.template

UI unresponsive to Kendo grid

Charvari I've been having issues with kendo grids for the following situations. I have a kendo grid with 18 columns. The user can select multiple rows. The number of rows is mostly over 10000. To get the selected row, I am using grid.select(). To extract conte

Kendo ui grid (if other conditions)

pilot What's wrong with my code? I have to check in the kendo UI grid if there is "OrderType 20" in the column. If so, I need to apply the css condition that includes the background, but it doesn't work, can anyone help me? thanks template: '# if (OrderType ==

Kendo UI Grid replacement fee

Juancho Ramone Are there any free/open source alternatives to Kendo UI Grid? I used to use the Grid module included in the free version, but don't use it anymore because it's too expensive for me because I only need the Grid module. Jarno Lahtinen I don't know

Kendo ui grid (if other conditions)

pilot What's wrong with my code? I have to check in the kendo UI grid if there is "OrderType 20" in the column. If so, I need to apply the css condition that includes the background, but it doesn't work, can anyone help me? thanks template: '# if (OrderType ==

Kendo UI grid dropdown and angular

Dalton 5 I try to set custom dropdown menu in Kendo UI. I have mentioned my problem. http://dojo.telerik.com/aFIZa/13 My problem is that I don't know how to set the selected text in the template property? I want to display the text field but save the ID as a v

Kendo UI Grid - Grouping Header

Ice Whisperer I want to implement Collapse/Expand all (in AngularJs) functionality for a grouped Kendo UI Grid and add it to the header of the Grid. Do you know how I can put my function there (see attached). Thanks! Dojo with normal grid with active grouping

Kendo UI Grid replacement fee

Juancho Ramone Are there any free/open source alternatives to Kendo UI Grid? I used to use the Grid module included in the free version, but don't use it anymore because it's too expensive for me because I only need the Grid module. Jarno Lahtinen I don't know

Kendo UI Grid with CSS Reference

blind I'm trying to write code that must conform to certain rules. Currently, I'm working on a part that looks like this: <head><link rel="stylesheet" href="Site.css"></head> <div class="row"> <div class="col-md-12"> @(Html.Kendo() .Gr

Kendo UI grid undefined decimal

Daniel Gustafson Here is my grid: $("#grid").kendoGrid({ dataSource: { type: "odata", transport: { read: { url: '/Discount/Get', dataType: "jsonp", type: "POST" },

Kendo ui grid (if other conditions)

pilot What's wrong with my code? I have to check in the kendo UI grid if there is "OrderType 20" in the column. If so, I need to apply the css condition that includes the background, but it doesn't work, can anyone help me? thanks template: '# if (OrderType ==

Kendo UI grid with multiple values

nyn3x I want to add kendo-ui-grid to my page which should contain columns with multi-values. Imagine the following data: | Name | Tag | |--------|---------------------| | John | C#, JavaScript, PHP | | Oliver | UI, SQL | | Mark

Kendo UI grid with multiple values

nyn3x I want to add kendo-ui-grid to my page which should contain columns with multi-values. Imagine the following data: | Name | Tag | |--------|---------------------| | John | C#, JavaScript, PHP | | Oliver | UI, SQL | | Mark

Kendo ui grid, merge filtering

username I'm using Kendo ui Grid(from Kendo Web) for remote binding (asp.net). I want to filter on some columns on the server side and on other clients. That is, I have columns order_id, user_name, amount`. If the user applies a filter on order_idor user_name-

Kendo ui grid, merge filtering

username I'm using Kendo ui Grid(from Kendo Web) for remote binding (asp.net). I want to filter on some columns on the server side and on other clients. That is, I have columns order_id, user_name, amount`. If the user applies a filter on order_idor user_name-