0

I have a kendo grid which is reading data from a remote json file. I want that the grid columns should also be read from the same json file so that I dont have to change the client side code again and again. Whatever comes in the json file it should be capable enough to present the same data without any hard coding on client side. My json file looks like

{ "data":[
    {"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":11,"UnitPrice":14.0000,"quanity":12},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":42,"UnitPrice":9.8000,"quanity":10},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":72,"UnitPrice":34.8000,"quanity":5},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10249,"ProductId":14,"UnitPrice":18.6000,"quanity":9}],
"columns":[
{"field":"_type","title":"Type"},{"field":"Discount","title":"Discount($)"},{"field":"OrderId","title":"Order ID"},{"field":"ProductId","title":"Product ID"},{"field":"UnitPrice","title":"Unit Price"},{"field":"quanity","title":"Quanity"}]
}

HTML code is as below

<div id="grid"></div>

JS code is below

 $("#grid").kendoGrid({
    title: { text: "Stats" },
    sortable: false,
    pageable: {
        pageSizes: true,
        buttonCount: 5
    },
    columnMenu: true,
    dataSource: {
        transport: {
            read: {
                url: "............/demo.json",
                dataType: "json"
            }
        },
        schema: {
            data: "data"
        }
    },
    columns: {
     //What should be done here.
 }
});

I tried the same transport read schema way to fetch the column data but it did not work. If I store the same columns json data in a variable and substitute that variable for columns then it works. Is there any way to store the columns json data as such in a variable from the json file. What is the best approach to achieve this behavior. Any help would be appreciated. Thanks in Advance.

pogo22
  • 137
  • 1
  • 5
  • 17
  • 1
    see this ans : http://stackoverflow.com/questions/24909618/how-to-bind-kendo-grid-with-system-data-datatable-at-runtime/24931517#24931517 and let me know if any concern. – Jaimin Jan 29 '15 at 06:42
  • Thanks.I am sorry I am not able to figure out how is this related to my requirement and how this can be used here. – pogo22 Jan 29 '15 at 06:57
  • 1
    What jaimin has provided exactly answers your question. In Jaimin's example he has wrote the whole JSON data hard coded which you want to retrieve via URL. – D_Learning Jan 29 '15 at 11:12
  • @pogo22 my link is exactly what you looking for. D_Learning already explain it to you. – Jaimin Jan 30 '15 at 05:22
  • Well if I have columns data in a variable like in this eg.var columns=[ {"field":"_type","title":"Type"},...];Then I am able to bind it to columns using columns:columns.Issue I am facing is how to get the data from json in "columns":[{},....] form and store the exact data [{},....] in a variable.Thanks – pogo22 Jan 30 '15 at 06:47
  • I am able to figure out the solution using http://stackoverflow.com/questions/23659321/binding-kendo-ui-grid-columns-headers-to-the-scope-in-angularjs Thanks All. – pogo22 Jan 30 '15 at 10:22

0 Answers0