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

[Solved] Bind Grid to JSON object?

5 Answers 388 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.
Sam Daniels
Top achievements
Rank 1
Sam Daniels asked on 24 May 2010, 04:08 PM
I'm curious if it's possible to bind a grid to a JSON object, much like it's done in the TreeView example here:


I'd like to be able to construct a JSON object that includes the entire grid, and then just bind the grid to the JSON object.  I don't want to bind the grid to my Model, and I don't want to have to statically define my columns.




5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 May 2010, 05:32 PM
Hi Sam Daniels,

It is possible to bind the grid to a JavaScript object. However the columns must be predefined. Here is a short code snippet:

var data = {data : [{CustomerID:1}, {CustomerID:2}], total:2 };
grid.dataBind(data);

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sam Daniels
Top achievements
Rank 1
answered on 24 May 2010, 06:50 PM
Thanks for the quick response.

Is this something that's likely to be implemented in a future release?  We are evaluating our options with Grids and we don't know the column names until run time.  I've looked at the AutoGeneratedColumn example, but our Model doesn't work for that either.  Ideally we would be able to create a JSON object that IS the grid, and then bind without having to predefine columns.

If it's not a current feature request, can we add it?

Thanks again,
Sam
0
Atanas Korchev
Telerik team
answered on 25 May 2010, 06:55 AM
Hi Sam Daniels,

We will consider this as a feature request and add it should more users start requesting it.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Godson Menezes
Top achievements
Rank 1
answered on 20 Sep 2010, 08:07 PM
Hello ,

My requirement is to search the list as you type for this I am trying to bind the grid to json object on onDataBinding ,but i am getting the grid object as undefined.
Here is the code,

 

 

 

View:

<
div id ="VisitPtList" >
  
<%= Html.Telerik().Grid<UserViewForms.PersonViewModel>()
  
.Name("Grid")
  
.Columns(columns =>
  
{
  
columns.Template(o => { }).Width(200).Title("Name");
  
columns.Template(o => { }).Width(200);
  
columns.Template(o => { }).Width(200);
  
columns.Template(o => { }).Width(100);
  
})
  
.ClientEvents(events => events
  
.OnDataBinding("onDataBinding")
  
)
  
.Sortable()
  
.Scrollable()
  
%>
  
</div>
  
  
  
var url = '<%= Url.Action("GetPersonList","PersonExistCheck") %>';
  
var grid = $(this).data('tGrid');
  
  
function onDataBinding(e) {
  
  
var sName = "test";
  
$.getJSON(url , { familyName: $('#Name').val() }, function(data) {
  
grid.dataBind(data);
  
});
  
   
  
  
}
  
  
Controller:
  
  
public ActionResult GetPersonList(string Name)
  
{
  
var data = GetPersons(Name);
  
  
return Json(data, JsonRequestBehavior.AllowGet);
  
}

Can you please provide me an sample to bind grid to json object. I want to do the search on client .

Thanks

0
Atanas Korchev
Telerik team
answered on 21 Sep 2010, 07:33 AM
Hello Godson Menezes,

 Try putting that code in the ondatabinding handler:

  
  
function onDataBinding(e) {
  
var grid = $(this).data('tGrid');

 
 
var sName = "test";
  
$.getJSON(url , { familyName: $('#Name').val() }, function(data) {
  
grid.dataBind(data);
  
});
}

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sam Daniels
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sam Daniels
Top achievements
Rank 1
Godson Menezes
Top achievements
Rank 1
Share this question
or