Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind a Kendo grid to a dynamic datatable
    primarykey
    data
    text
    <p>I am working with Kendo+razor and I want to create a Kendo grid that does not have any specific data model (in my case, I have to show the results of a SQL query, entered by user, so the result can have any number/type of columns). To make it generic I tried to bind the grid to System.data.DataTable and an ajax call to populate that grid. It works fine when loaded for the first time, but when I repopulate the same grid, it does not update its column names.</p> <p>Scenario:<br> Ajax call is made on a button click to populate grid with the query results. On first ajax call the result was a JSON with attributes id, name, and description. The grid showed correct data with the 3 above mentioned columns and 4 rows.<br> On the second ajax call the response JSON contains attributes UserName, UserType, Address, PhoneNumber, this time the grid does not update its model binding and columns remain the previous three columns id, name, and description but the number of rows gets updated with no data in it (as the columns are not present in the returned JSON)</p> <p>I want to rebind the columns to the returned JSON attributes that can differ every time.</p> <p>Here is my HTML code:</p> <pre><code>@model System.Data.DataTable &lt;div&gt; @(Html.Kendo().Grid(Model) .Name("ResultsGrid") .TableHtmlAttributes(new { Class = "kendoGrid" }) ) &lt;/div&gt; </code></pre> <p>and the Javascript on button click code:</p> <pre><code>function execute() { $.ajax({ url: "something something", type: "GET", contentType: "application/json;charset=utf-8", data: "", dataType: "json", success: function (data) { $("#ResultsGrid").kendoGrid({ scrollable: false, pageable: true, sortable: true, resizable: true, dataSource: { data: data, pageSize: 5 } }); } } </code></pre> <p>How can I refresh the grid to bind to columns to the new JSON attributes?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload