I've been trying to use the PHP wrapper for UI and get the grid to display my JSON data. If I set $dataSource->data($json) where $json is the result from my call it works, but when I set it to $dataSource->transport($transport) where $transport contains my read transport I get no rows to display in the grid.
I'm using the CodeIgniter framework and have the require statements as part of my autoload, so they are there along with the requirements in the header.
Here is my code:
<?php
//$json = json_decode(file_get_contents(site_url('data/sys_settings/read')),true);
$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url(site_url('data/sys_settings/create'))
->contentType('application/json')
->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url(site_url('data/sys_settings/read'));
$update = new \Kendo\Data\DataSourceTransportUpdate();
$update->url(site_url('data/sys_settings/update'))
->contentType('application/json')
->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url(site_url('data/sys_settings/destroy'))
->contentType('application/json')
->type('POST');
$transport->read($read)
->parameterMap(new \Kendo\JavaScriptFunction('function(data) {
return kendo.stringify(data)
}'));
$idField = new \Kendo\Data\DataSourceSchemaModelField('id');
$idField->type('number')
->editable(false)
->nullable(false);
$repId = new \Kendo\Data\DataSourceSchemaModelField('rep_id');
$repId->type('number')
->editable(false)
->nullable(false);
$col1Field = new \Kendo\Data\DataSourceSchemaModelField('key');
$col1Field->type('string')
->editable(false)
->nullable(false);
$col2Field = new \Kendo\Data\DataSourceSchemaModelField('val');
$col2Field->type('string')
->editable(true)
->nullable(true);
$model = new \Kendo\Data\DataSourceSchemaModel();
$model->addField($idField)
->addField($repId)
->addField($col1Field)
->addField($col2Field);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
->errors('errors')
->model($model)
->total('total');
$dataSource = new \Kendo\Data\DataSource();
$dataSource->transport($transport)
->pageSize(20)
->serverFiltering(true)
->type('odata')
->schema($schema);
$col1 = new \Kendo\UI\GridColumn();
$col1->field('key')
->width(120)
->title('Settings');
$col2 = new \Kendo\UI\GridColumn();
$col2->field('val')
->width(120)
->title('Value');
$command = new \Kendo\UI\GridColumn();
$command->addCommandItem('edit')
->addCommandItem('destroy')
->title(' ')
->width(250);
$grid = new \Kendo\UI\Grid('grid');
$grid->addColumn($col1,$col2,$command)
->dataSource($dataSource)
->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'))
->editable('inline')
->sortable(true);
echo $grid->render();
here is my JSON being sent from the URL:
{"data":[{"id":"1","rep_id":"0","key":"default_country","val":"USA"},{"id":"2","rep_id":"0","key":"default_state","val":"CA"},{"id":"4","rep_id":"0","key":"default_account_type","val":"Customer"},{"id":"5","rep_id":"0","key":"default_title","val":null}],"total":4,"errors":null}
I'm not sure what I'm doing wrong, but I can't get it to work via the transport. Any help would be greatly appreciated.