Binding to a collection of dynamic objects

Thread is closed for posting
7 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 01 Aug 2012 Link to this post

    Requirements

    Kendo UI Suite and Version

    2012.2.710 

    jQuery Version

    1.7.1 

    Supported Browsers and Platforms

    All supported by Kendo UI 

    Components/Widgets used 

    Grid 

    ASP.NET MVC Version

    4.0


    PROJECT DESCRIPTION 
    This project demonstretes how to populate Grid component with collection of dynamic objects. 
  2. CC135033-639D-4C74-A6BA-4AF5E3E1414F
    CC135033-639D-4C74-A6BA-4AF5E3E1414F avatar
    4 posts
    Member since:
    Jan 2013

    Posted 22 Mar 2013 Link to this post

    Sorry but this sample is'nt dynamic because in the body of grid declaration, you put this:

    ( m.Id("ProductID");
     m.Field("ProductID", typeof(int));
     m.Field("ProductName", typeof(string));
     m.Field("UnitPrice", typeof(decimal));
     m.Field("QuantityPerUnit", typeof(string));  )

    This column declarations is static, this means that you have alredy know column names. The ideal case is that you can bind column names with a list of items for example 
  3. 0E275D6B-7F31-41BF-B0D3-7F311B204FEF
    0E275D6B-7F31-41BF-B0D3-7F311B204FEF avatar
    8 posts
    Member since:
    May 2012

    Posted 09 Apr 2013 Link to this post

    Is there an example with really dynamic object with all CRUD operations ? (Because Datatable is not supported for CRUD inline editing)

    http://www.kendoui.com/forums/mvc/grid/problem-with-crud-operation-with-data-table-as-model.aspx

    Kind Regards

    Paul
  4. 035262A8-3C22-4BDF-AEEA-E72D69CB116E
    035262A8-3C22-4BDF-AEEA-E72D69CB116E avatar
    71 posts
    Member since:
    Apr 2012

    Posted 31 Jul 2013 Link to this post

    This was never dynamic as mentioned by another user. Where are the dynamic columns, static columns are easy...
  5. 72856148-6402-453D-855E-EA5C18B5D4D2
    72856148-6402-453D-855E-EA5C18B5D4D2 avatar
    3 posts
    Member since:
    Aug 2013

    Posted 17 Oct 2013 Link to this post

    Did anybody find out how to handle dynamic columns?

    On a related note, Grid doesn't seem to handle nested references as in:

    [{ 1: { x: ..., y:, ... }, ...]
    1.x
    1.y

  6. 0D392CF8-46D3-49E2-9830-AC45C4122877
    0D392CF8-46D3-49E2-9830-AC45C4122877 avatar
    2 posts
    Member since:
    May 2012

    Posted 26 Nov 2013 Link to this post

    Don't know if this issue is solved, but below is one example of code for creating a dynamic grid. Don't forget the IEnumerable<dynamic> row.


    @model IEnumerable<dynamic>
    @{
    ViewBag.Title = "Home Page";
    }

    @(Html.Kendo().Grid(Model).Name("Customers")
    .DataSource(ds => ds.Ajax()
    .Model(m =>
    {
    m.Id("CustomerId");
    m.Field("CustomerId", typeof(int));
    m.Field("Name", typeof(string));
    m.Field("City", typeof(string));
    m.Field("Country", typeof(string));
    })
    .Read(r => r.Action("Read", "Home"))
    .Update(u => u.Action("Update", "Home"))
    .Destroy(u => u.Action("Destroy", "Home"))
    .Create(u => u.Action("Create", "Home"))
    )
    .ToolBar(toolBar => toolBar.Create())
    .Columns(columns =>
    {
    columns.Bound("CustomerId");
    columns.Bound("Name");
    columns.Bound("City");
    columns.Bound("Country");
    columns.Command(command =>
    {
    command.Edit();
    command.Destroy();
    });
    })
    .Editable(editable => editable.TemplateName("CustomerItem").Mode(GridEditMode.PopUp))
    .Pageable()
    .Sortable()
    .Groupable()
    .Filterable()
    )
  7. 4E27E0B0-96A6-4C48-8D04-477F6D343F67
    4E27E0B0-96A6-4C48-8D04-477F6D343F67 avatar
    1 posts
    Member since:
    Jan 2013

    Posted 02 Jan 2014 Link to this post

    After researching for a while with no luck I finally found a solution.  Here are the details. 

    Problem:  I want to generate dynamic columns in the grid every refresh.  Because my columns are based on an hour and date dimension which you would imagine are going to change every hour and hence would have a different name every time.  However i still want to generate columns on the fly and show them with nice display labels as date

    Solution: So i figured since I am getting Json data what should i do.  Here is my solution. 

    Note that If try to pass pre-formatted string as the Key in JSon i.e. 03/01/2014.  it would break the grid because the key in json has to comply with javascript variable naming conventions.  So as a work around instead of passing the data string in json key i am passing something like "d03_01_2014".  Once the gird is bound to the data i would loop through the columns collection of the kendo gird and rename/replace unwanted characters (i.e. 'd' and '_') with the ones i want. 

    below is the function that would create my grid
    01.function createGrid10Days(data) {
    02.$("#grid10Days").kendoGrid({
    03.    dataSource: {
    04.        type: "json",
    05.        data: data,
    06.        pageSize: 20
    07.    },
    08.    height: 605,
    09.    scrollable: false,
    10.    pageable: {
    11.        input: true,
    12.        numeric: false
    13.    },
    14.    sortable: true
    15. 
    16.});}
    then upon document ready i can make calls to get JSon data and pass it to the create method above and do the renaming of columns afterwards as shown below.
    //First Create My HTML grid the usual way.  Pass in the JSON Data to the create grid method.
    createGrid10Days(data);
                                 
    //Right after the grid is created, rename the columns by looping through it                           
    var g = $("#grid10Days").data("kendoGrid");
    for (i = 0; i < g.columns.length ; i++)
    {
         var oldFName = g.columns[i].field;
         var newFName = oldFName.replace("d", "");
         newFName = newFName.split("_").join("/");
         $("#grid10Days thead [data-field=" + oldFName + "] .k-link").html(newFName);
    }

    Hope this helps if you are same as my situation.

    reference: 
    http://www.telerik.com/forums/how-do-you-change-the-column-header-text-in-javascript
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.