This is a migrated thread and some comments may be shown as answers.

Column type and formatting questions for dynamic data

1 Answer 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 14 Feb 2013, 12:47 AM
I have a grid where the columns are dynamic.  By default (no schema set) all the columns are strings which causes the sorting to not be that helpful.

I use a web service that returns json to get the data for the grid, can I define the column types there or would that be a separate call?

Once I know the column types is it possible to set the column format based on the type? 

I have some code that defines the field type for columns if I know their exact name but that isn't very practical because there are many different possible column names.
schema: {
    model: {
        fields: {
            ReportDate: {
                type: "date"
            },
            Age: {
                type: "number"
            }
        }
    }
}
I also have some code that sets the template or format for a given column but it is also hard coded and not scalable.
//make first column a link using values from two columns
columns[0].template = "<a href='somepage.html?rid=#=ReportID#' target='_blank'>#=ReportNum#</a>";
 
//make sure value in 3rd column is formatted as a date
columns[2].format = "{0:M/d/yyyy h:mm tt}";
Any help would be appreciated. 

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Feb 2013, 09:25 AM
Hello Jason,

My recommendation is to use two separate $.ajax calls. The DataSource and Grid's settings should be defined during the initialization of the components, changing field type/name or column properties at runtime is not supported. You may retrieve the settings with one $.ajax call and initialize the grid at its success event.

When the grid is build it will issue second ajax request (using the read transport) to retrieve the data.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or