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

Setting column defenitions within a datasource read

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 1
Danny asked on 21 Aug 2014, 08:15 AM
Hi, 

Is there a way to set the column definitions of a grid within its datasource read-function?

We need to retrieve the data from the server and want to use server-side paging, hereby the column-definitions come directly from the server and are not known before the datasource read is called and can not be defined on the grid directly when initializing it.

I have made an example  to illustrate the porblem.

http://dojo.telerik.com/IWiqo/7

3 Answers, 1 is accepted

Sort by
0
DavidOBrien
Top achievements
Rank 2
answered on 21 Aug 2014, 09:47 PM
What kind of page is it? .net , php , jsp? plain html?

On most of my more complex pages I have a database table with the column definitions in it already and read them when the page generates for both the schema definition and grid columns definition

schema: {
                            data: "data",
                            total: "total",
                            model: {
                                id: "EmailID",
                                fields: {
<?php
  foreach ( $columns as $key => $value ) {
   echo str_repeat("\t",8) . $value['field'] . ': { editable: ' . $value['editable'] . ', type: "' . $value['type'] . '"},'."\n";
  }
?>
                                }
                            }
                        }

$("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true,
                        toolbar: ["create","save","cancel"],
                        columns: [
                            { command: ["edit", "destroy"], title: " ", width: 190 },
<?php
   foreach ( $columns as $key => $value ) {
     echo str_repeat("\t",7) . "{" .
     ( !
empty( $value['field'] ) ? "field:'" . $value['field'] . "'," : '' ) .
     ( !
empty( $value['title'] ) ? "title:\"" . $value['title'] . "\"," : '' ) .
     ( !
empty( $value['width'] ) ? "width:" . $value['width'] . "," : '' ) .
     ( !
empty( $value['template'] ) ? "template:'" . $value['template'] . "'," : '' ) .
     ( !
empty( $value['headerTemplate'] ) ? "headerTemplate:\"" . $value['headerTemplate'] . "\"," : '' ) .
     ( !
empty( $value['editor'] ) ? "editor:" . $value['editor'] . ","    : '' ) . "},\n";
   }
?>
                        ],
                        editable: {
                            mode: "popup",
                        },
                        sortable: true,                       
                    });

0
Danny
Top achievements
Rank 1
answered on 22 Aug 2014, 08:04 AM
It is an .Net page. 

We receive the column-definitions together with the data that we need to show. In your solution we need to do two calls to the server. one to retrieve the column-definitions and a second one to receive the actual data. This is not desirable within our application.


0
Dimo
Telerik team
answered on 22 Aug 2014, 02:27 PM
Hi Danny,

The described combination of requirements is unfortunately not supported.

If you sacrifice one of the requirements below, then the scenario becomes possible to implement.

- single request, which includes both configuration settings and data
- server data operations (paging, sorting, filtering, editing)
- usage of non-string data fields for data operations

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