This is a migrated thread and some comments may be shown as answers.

[Solved] Grid ajax binding getting called twice

2 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Atanu
Top achievements
Rank 1
Atanu asked on 12 Oct 2012, 08:38 AM
I have a grid like this. The grid is inside a partial view.

@{
    Html.Kendo().Grid<IEnumerable.............>()
    .Name("IniParamGrid")
    .HtmlAttributes(new { style = "width: 100%;" })
    .Events(events => events.DataBound("Grid_onRowDataBound"))
    .Events(events => events.Change("Grid_OnRowSelectUID"))
    .AutoBind(false)
    .Columns(col =>
    {
        col.Bound("NP_PARAM_UID").Hidden();        
        col.Bound("PROCESS_GRP").Title("Process Group").HeaderHtmlAttributes(new { style = "text-align:center;" });
        col.Bound("PARAM_NAME").Title("Parameter Name").HeaderHtmlAttributes(new { style = "text-align:center;" });
        col.Bound("PARAM_VALUE").Title("Parameter Value").HeaderHtmlAttributes(new { style = "text-align:center;" });
        col.Bound("EXTERNAL_ID").Title("Table Name").HeaderHtmlAttributes(new { style = "text-align:center;" });
        col.Bound("EXTERNAL_FK").Title("Key Value").HeaderHtmlAttributes(new { style = "text-align:center;" });
        col.Bound("DEL_FLG").Hidden();
    })
    .DataSource(dataBinding =>
    {
        dataBinding.Ajax().Read(read => read.Action("SrchDataIniParam", "Admin",
            new
                {
                    area = "Admin",
                    strParam1 = ViewBag.Param1,               
                }))
                .ServerOperation(false);
    })
    .Resizable(resizing => resizing.Columns(true))
    .Selectable() 
    .Reorderable(reorder => reorder.Columns(true))
    .Pageable()
    .Sortable()
    .Filterable()
    .Render();
}

My Controller code looks like this

[HttpPost]
public ActionResult SearchIniInitiator(string txtSrchPrGrp)
{
    ViewBag.Param1 = txtSrchPrGrp;         
    return PartialView("SubForms/_Search");
}
 
public ActionResult SrchDataIniParam(string strParam1, [DataSourceRequest] DataSourceRequest request)
{
    MyDate objdata = new MyDate ();
    return Json(objdata .getListstrParam1).ToDataSourceResult(request));
}

I am submitting the form from javascript (form.submit()) which call the "SearchIniInitiator" action result which inturn calls the "SrchDataIniParam" param to populate the grid. This is working as expected.
But what I see is that the "SrchDataIniParam" function is getting called twice.

The same code is working with Telerik grid perfectly but why Kendo grid is calling it twice.

Please help.

2 Answers, 1 is accepted

Sort by
0
Mic
Top achievements
Rank 1
answered on 05 Nov 2012, 04:35 PM
Anybody? Is this issue fixed? I have the same problem and i dont know what to do
0
Atanu
Top achievements
Rank 1
answered on 06 Nov 2012, 04:07 AM
Hi Mic,

This is the reply I got from Kendo Team....Hope this helps

---- Clicking the header of sortable grid will cause the grid to toggle the sort expression based on the clicked column, i.e will start with { field: "current field", dir:"asc"} etc.You cannot prevent that behavior. However you can attach the event once the Grid is initialized.

$(function() {
 $("#grid").data("kendoGrid").bind("dataBinding", function(e) {
  e.preventDefault();
 });
});

Preventing dataBinding of the Grid will cause only the repaint of the Grid, but will not cause the prevention of the request from the DataSource or refresh on any other widgets that shares that DataSource widget.---------
Tags
Grid
Asked by
Atanu
Top achievements
Rank 1
Answers by
Mic
Top achievements
Rank 1
Atanu
Top achievements
Rank 1
Share this question
or