0

I am using kendu grid with report data,grid is working perfectly in normal case but my problem is that column and schema property of grid will not be static, that's why i want to add it dynamically,but I am unable to set it.

Here is my code:

$(document).ready(function () {
                var obj = {
                    fields: {
                    }
                };
                var Column1;

              $("#grid").kendoGrid({
                    dataSource: {
                        type: "data",
                        transport: {
                            read: function (options) {
                                $.ajax({
                                    type: "GET",
                                    url: "http://localhost:3833/Service1.svc/GetJSON1",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (msg) {
                                        var t2 = msg.GetJSON1Result;
                                        var data1 = $.parseJSON(t2.data);

                                        Column1 = t2.columns;
                                        var t11 = Column1;
                                        obj = {
                                            fields: {
                                            }
                                        };
                                        $.each(Column1, function (i, value) {
                                            obj.fields[value.field] = { type: "number" };
                                        }
                                        );
                                        var Schema1 = {
                                            model: obj
                                        }
                                        var gridDetails = $("#grid");
                                        **//Setting schema to grid but it's not effective**
                                        gridDetails.schema = Schema1;
                                        **//Setting schema to grid but it's not effective**
                                        gridDetails.columns = Column1;
                                        options.success(data1);
                                        options.success(Schema1);
                                        options.success(Column1);

                                    }
                                });
                            }
                        },

                        pageSize: 50,
                        serverFiltering: false ,
                        serverSorting: false,
                        serverPaging: false,
                    },
                    height: 550,
                    reorderable: true,
                    filterable: true,
                    sortable: true,
                    pageable: true,
                    scrollable: true,
                    resizable: true,
                    groupable: true

                });
            });

please help me. I am new to kendu


Regards, Ajeet Kumar

Ajeet
  • 9
  • 9
  • See this http://stackoverflow.com/questions/24909618/how-to-bind-kendo-grid-with-system-data-datatable-at-runtime/24931517#24931517 – Jaimin Sep 24 '14 at 06:46

1 Answers1

0

To change the grid columns you need to destroy it first and then initialize it again. Here is some code:

var grid = $("#grid").data("kendoGrid");
var options = grid.options;
grid.destroy();
options.columns = [ /* set the columns */ ];
grid.destroy();
$("#grid").empty().kendoGrid(options);
Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93