Data grid not showing on successful GET request

5 posts, 0 answers
  1. Richard
    Richard avatar
    5 posts
    Member since:
    Mar 2017

    Posted 21 Mar Link to this post

    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();

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1966 posts

    Posted 23 Mar Link to this post

    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.
  3. Richard
    Richard avatar
    5 posts
    Member since:
    Mar 2017

    Posted 27 Mar in reply to Boyan Dimitrov Link to this post

    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!

  4. Richard
    Richard avatar
    5 posts
    Member since:
    Mar 2017

    Posted 27 Mar in reply to Richard Link to this post

    I've found answer myself, 'length' is the answer. Thanks a lot for your help. Please feel free to close this topic.
  5. Richard
    Richard avatar
    5 posts
    Member since:
    Mar 2017

    Posted 27 Mar in reply to Richard Link to this post

    I've found answer myself, 'length' is the answer. Thanks a lot for your help. Please feel free to close this topic.
Back to Top