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

[Solved] Error with dataBind() and Grid

1 Answer 40 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.
Greg
Top achievements
Rank 1
Greg asked on 01 Sep 2011, 09:10 PM
So, I've got this grid, and I'm using an Ajax call to update it.  I can't do it the way suggested in the demo or manual, because it relies on values from selects on the page.  So, using the client-side api, I've implemented updating.  However, it does not seem to work.

In Firefox 6, I get an error this.dataSource is undefined.
In Chrome, I get "Uncaught TypeError: Cannot call method 'success' of undefined"

Here's my code for the grid:
@(Html.Telerik().Grid(Model)
    .Name("DataTable")
    .Columns(columns =>
    {
        columns.Bound(c => c.LastName);
        columns.Bound(c => c.FirstName);
    }
    )
    .Pageable()
    .Footer(true)
    .Sortable()
)

The Javascript:

function (data) {
            var grid = $("#DataTable").data("tGrid");
            var gridContents = data.Data;
            grid.dataBind(gridContents);
}


And the code that returns the data:


return Json(new
                {
                    Data = new GridModel { Data = grid, Total = grid.Count },
                    TotalCount = users.Count,
                    Results = CourseResults
                }, JsonRequestBehavior.AllowGet);

The other members of the returned JSON object are for other parts of the page.

Any ideas?


1 Answer, 1 is accepted

Sort by
0
Greg
Top achievements
Rank 1
answered on 02 Sep 2011, 02:01 PM
Ok, I found my solution in this thread. Basically, you have to set databinding to ajax and give it an empty grid model in the select method for this to work (this seems like a bug to me.)

@(Html.Telerik().Grid(Model)
    .Name("DataTable")
    .DataBinding(db => db.Ajax().Select("_BlankGrid", "AJAX"))

and then in the mentioned action:

/// <summary>
/// Total hack.
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
[GridAction]
public ActionResult _BlankGrid(GridCommand command)
{
    return View(new GridModel { Data = null, Total = 0 });
}
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Greg
Top achievements
Rank 1
Share this question
or