Creating a Custom Grid Column and fill data

2 posts, 0 answers
  1. Mr.
    Mr. avatar
    1 posts
    Member since:
    Jun 2010

    Posted 25 May 2016 Link to this post

    I have received the data in json format as follows:

    var mydata = [
    {
    "Title":"My Grid Example",
    "NumberOfColumns":4,
    "DatasetHeader":{"items":[
    {"Name":"FullName","Type":"System.String"},
    {"Name":"Age","Type":"System.Int32"},
    "Name":"Address","Type":"System.String"},
    {"Name":"Cost","Type":"System.Double"}
    ]},
    "Rows":["items":[
    {"Rohan","12","Arab","234"},
    {"Radha","11","Texas","123"},
    {"Haris","22","NPL","344"},
    {"Christine","23","Arab","674"},
    {"Tot","22","UK","434"},
    {"Terry","21","LA","334"},
    {"Savana","19","SA","224"}
    ]}
    }];

    Now, I want to generate the dynamic grid with the above data with 4 columns and 7 rows (for this case) . The columns can varies during runtime (from 2-3 to 14-15)

    Something like this is expected:

    <script>

    $(document).ready(function () {

    generateGrid(mydata);

    }

    function generateGrid(receiveddata) {

    $("#table-grid").kendoGrid({

    dataSource: { data: receiveddata.Rows.Items},

    height: 400,
    scrollable: true,

    schema: {
            model: receiveddata.DatasetHeader.items
          },

    title: receiveddata.title

    });

    } //end of javascript function

    </script>

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

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1985 posts

    Posted 30 May 2016 Link to this post

    Hello,

    From what I could see, the items collection in the Rows does not contain valid JSON structure, so it will not be possible to use that data in the Grid. You could however parse it to a valid data before passing it to the dataSource and the model of the widget:
    Additionally, for all sides convenience, please use the correct product section when you open new threads. Thank you for your understanding.


    Best Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top