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

Data grid not showing on successful GET request

4 Answers 357 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 21 Mar 2017, 01:16 PM

Hello,

I have a condiderble issue with Kendo UI Grid.

First of all, it loads data by AJAX call after loading grid itself instead od loading and inserting data on server.

But back to my issue, with this code, my grid is generated, it calls AJAX request, but it doesn't show them in grid.

Code:

$transport = new \Kendo\Data\DataSourceTransport();

$read = new \Kendo\Data\DataSourceTransportRead();

$read->url('http://127.0.0.1/api/records')
->contentType('application/json')
->type('GET');

$create = new \Kendo\Data\DataSourceTransportCreate();

$create->url('http://127.0.0.1/api/records')
->contentType('application/json')
->type('POST');

$update = new \Kendo\Data\DataSourceTransportUpdate();

$update->url('http://127.0.0.1//api/records')
->contentType('application/json')
->type('UPDATE');

$destroy = new \Kendo\Data\DataSourceTransportDestroy();

$destroy->url('http://185.33.145.45/api/records')
->contentType('application/json')
->type('DELETE');

$transport
->read($read)
->create($create)
->update($update)
->destroy($destroy)
->parameterMap('function(data) {
return kendo.stringify(data);
}');

$model = new \Kendo\Data\DataSourceSchemaModel();

$IDField = new \Kendo\Data\DataSourceSchemaModelField('id');
$IDField->type('number')
->editable(false)
->nullable(true);

$nameField = new \Kendo\Data\DataSourceSchemaModelField('name');
$nameField->type('string')
->validation(array('required' => true));

$YearField = new \Kendo\Data\DataSourceSchemaModelField('year');
$YearField->type('number')
->editable(true)
->nullable(true);

$model
->addField($IDField)
->addField($YearField)
->addField($nameField);

$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
->errors('errors')
->model($model)
->total('total');

$dataSource = new \Kendo\Data\DataSource();
$dataSource
->transport($transport)
->pageSize(30)
->schema($schema);

$grid = new \Kendo\UI\Grid('grid');

$name = new \Kendo\UI\GridColumn();
$name
->field('name')
->title('název');

$year = new \Kendo\UI\GridColumn();
$year
->field('year')
->title('rok vydání');

$excel = new \Kendo\UI\GridExcel();
$excel->fileName('Kendo UI Grid Export.xlsx')
->filterable(true)
->proxyURL('excel-export.php?type=save');

$grid
->addColumn($name, $year)
->dataSource($dataSource)
->excel($excel)
->groupable(true)
->sortable(true)
->filterable(true)
->navigatable(true)
->editable(true)
->pageable(true)
->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'),
new \Kendo\UI\GridToolbarItem('save'), new \Kendo\UI\GridToolbarItem('cancel'))
->height(400);

$gridHTML = $grid->render();

4 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 23 Mar 2017, 11:01 AM

Hello Richard,

I noticed that schema.data is set to "data" in the provided code. Basically this will look for a field "data" in the response for find the data items. I guess that in the response returned from the server items are set on root level of the response or other field. Could you please provide the exact response returned from the server? 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Richard
Top achievements
Rank 1
answered on 27 Mar 2017, 11:51 AM

Hello Boyan,

thanks a lot for your answer. All I had to due was changing schema.data from "data" to "".

I return items as single JSON. Could you please advice me, how should I edit my total field to show total count of items? Thanks in advance!

0
Richard
Top achievements
Rank 1
answered on 27 Mar 2017, 11:59 AM
I've found answer myself, 'length' is the answer. Thanks a lot for your help. Please feel free to close this topic.
0
Richard
Top achievements
Rank 1
answered on 27 Mar 2017, 11:59 AM
I've found answer myself, 'length' is the answer. Thanks a lot for your help. Please feel free to close this topic.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Richard
Top achievements
Rank 1
Share this question
or