Unable to Get "Grid Batch Editing" to Render

13 posts, 0 answers
  1. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 27 Mar 2013 Link to this post

    Hello Guys,

    I am trying to get the "Grid Batch Editing"  PHP code  http://demos.kendoui.com/web/grid/editing.html to render but I am unable to do so. I am using a MySQL database and the connection is working fine. There is data in the database but I am not able to get any data to display with Kendo. I have made a simple table with just one field I want to display as I am learning to use Kendo. See my code below:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <link href="../../kendouiphp/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
            <link href="../../kendouiphp/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
            <script src="../../kendouiphp/js/jquery.min.js"></script>
            <script src="../../kendouiphp/js/kendo.all.min.js"></script>
        </head>

    <body>
    <form class="form" action="doctorsKendoUiCrud.php" method="post" id="DoctorCrudGridForm" onsubmit="">


    <?php

    // Kendo UI CRUD Grid for doctors
    // follow:
    //            http://demos.kendoui.com/web/grid/editing.html
    //            http://www.kendoui.com/forums/php/grid/php-wrappers---pdo.aspx


    require_once '../../kendouiphp/wrappers/php/lib/DataSourceResult.php';
    require_once '../../kendouiphp/wrappers/php/lib/Kendo/Autoload.php';
    require_once("../../admin/lib/pdo.sql.php");
    require_once("../../admin/AdminObject.php");


    //$result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*******');
    $admin_object = new AdminObject();

    //$admin_object->die_array($_GET);
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //if ($_SERVER['REQUEST_METHOD'] == 'GET') {
        //die("We are here");
        header('Content-Type: application/json');
        $request = json_decode(file_get_contents('php://input'));
        //$result = new DataSourceResult('sqlite:../../sample.db');
        $result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*********');
        $type = $_GET['type'];
        $columns = array('doctor_id', 'doctor_firstname');
     
        
        switch($type) {
            case 'create':
                $result = $result->create('doctors', $columns, /*$request->models,*/ 'doctor_id');
                break;
            case 'read':
                //$result = $result->read('doctors', $columns, $request);
                $result = $result->read('doctors', $columns);
                break;
            case 'update':
                $result = $result->update('doctors', $columns, /*$request->models,*/ 'doctor_id');
                break;
            case 'destroy':
                $result = $result->destroy('doctors', /*$request->models,*/ 'doctor_id');
                break;
        }
        
        echo json_encode($result);
        
        exit;
    }

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

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

    $create->url('doctorsKendoUiCrud.php?type=create')
         ->contentType('application/json')
         ->type('POST');

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

    $read->url('doctorsKendoUiCrud.php?type=read')
         ->contentType('application/json')
         ->type('POST');

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

    $update->url('doctorsKendoUiCrud.php?type=update')
         ->contentType('application/json')
         ->type('POST');

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

    $destroy->url('doctorsKendoUiCrud.php?type=destroy')
         ->contentType('application/json')
         ->type('POST');

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

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

    $doctorIDField = new \Kendo\Data\DataSourceSchemaModelField('doctor_id');
    $doctorIDField->type('number')
                   ->editable(false)
                   //->nullable(true);
                   ->nullable(false);

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

    $model->id('doctor_id')
        ->addField($doctorIDField)
        ->addField($doctorNameField);


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

    //echo "This is the schema <br />\n<br />\n<br />\n";var_export($schema);die();

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

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

    $doctorName = new \Kendo\UI\GridColumn();
    $doctorName->field('doctor_firstname')
                ->title('Doctor Name');

    $command = new \Kendo\UI\GridColumn();
    $command->addCommandItem('destroy')
            ->title('&nbsp;')
            ->width(110);

    //echo "This is the Doctors Grid PreSet <br />\n<br />\n<br />\n";var_export($grid);die();

    $grid->addColumn($doctorName)
         ->dataSource($dataSource)
         ->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'),
            new \Kendo\UI\GridToolbarItem('save'), new \Kendo\UI\GridToolbarItem('cancel'))
         ->height(400)
         ->navigatable(true)
         ->editable(true)
         ->pageable(true);

    //echo "This is the Doctors Grid PostSet <br />\n<br />\n<br />\n";var_export($grid);die();

    echo $grid->render();

    ?>   
        
    </form>
    </body>
    </html>


    Please let me know what I am doing wrong.
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 29 Mar 2013 Link to this post

    Hello Christian,

    We are not sure what exactly could be the issue with the code you shared. Are there any JavaScript errors in the console?

    If not could you please send us that sample project you are trying so we can see what is going wrong?

    Kind regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET AJAX banner
  4. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 29 Mar 2013 Link to this post

    Hello Vladimir,

    This is the ONLY file I have for this project other than the Kendo library package in my project. I guess I am confused as I must have another file read this file?? What other files do I need to get this page to work?

    Please explain as I am learning all this.

    Thank you.

    Christian
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 02 Apr 2013 Link to this post

    Hi Christian,

     
    I am not sure what exactly is going wrong on your side.

    I tried to setup an example scenario on our side using the Northwind database (similar to the way you did) and everything is working as expected. 

    Please find in the attached files the minimum setup required to run the Northwind Customers table:

    Basically you need to cover the following:

    • create database using the attached script
    • setup the connection string according to your database instance
    • make sure that the paths pointing to the Kendo files are properly configured.

    Kind Regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Hello Vladimir,

    Thank you for this example project you provided. I setup your project on my local workspace. In your index file there is a line:
    $request = json_decode(file_get_contents('php://input'));

    Here is the error I get:
    <b>Warning</b>: file_get_contents(../../lib/DataSourceResult.php) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in <b>/var/www/pub/MetroRelations/kendouiphp/wrappers/php/include/footer.php</b> on line <b>29</b><br />

    What is the input file? I cannot get the page to work since this file is missing. I am not understanding where this file is supposed to come from.

    There seems to be other pieces I am missing that I do not understand. Please explain.

    Thank you.

    Christian
  7. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Hello Vladimir,

    I fixed the above error, I had to setup the file paths references located in the footer.php file in reference to the index.php file.

    Please see my posts below for my original problem.

    Thank you.

    Christian
  8. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Hello Vladimir,

    I have attached the view source code as an html file so you can see what I get when I render this project you gave me.

    Please let me know what I am doing incorrectly.

    Thank you.

    Christian
  9. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Hello Vladimir,

    For "Grid Batch Editing"  PHP code  http://demos.kendoui.com/web/grid/editing.html I am able to get the page to render with values from database, BUT I am unable to use any of the Add, Delete and Update functionalities on this page. Also when I first render the page there is "NaN", I get "NaN - NaN of 305 items", BUT after I hit any arrow button it changes to "1 - 305 of 305 items".

    Again please help.

    Thank you.

    Christian

  10. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 11 Apr 2013 Link to this post

    Hello Vladimir,

    I had made a few changes to my code.

    You can see my  "Grid Batch Editing"  PHP page here.  And the code is attached below, ONLY look at the doctorsKendoUiCrudBuildingLatest.zip file, ignore the other two files.

     So you can see where I am not getting the page to render.

    Again please help.

    Thank you.

    Christian


  11. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 12 Apr 2013 Link to this post

    Hi Christian,

     
    After reviewing the provided link it seems that the grid is not loaded with data because the JSON response from the server includes HTML code (please check this screencast). I would suggest to move the header of the document to external file and include in the following way:

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        header('Content-Type: application/json');
         
        $request = json_decode(file_get_contents('php://input'));
     
        $result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*****');
        $type = $_GET['type'];
        $columns = array('doctor_id', 'doctor_firstname');
             
        switch($type) {
            case 'create':
                $result = $result->create('doctors', $columns, $request->models, 'doctor_id');
                break;
            case 'read':
                $result = $result->read('doctors', $columns, $request);
                //$result = $result->read('doctors', $columns);
                break;
            case 'update':
                $result = $result->update('doctors', $columns, $request->models, 'doctor_id');
                break;
            case 'destroy':
                $result = $result->destroy('doctors', $request->models, 'doctor_id');
                break;
        }
         
        echo json_encode($result);
         
        exit;
    }
    //load the header of the document here
    require_once '../../include/header.php';
    Kind Regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  12. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 12 Apr 2013 Link to this post

    Hello Vladimir ,

    Thank you very much for the screen cast! That was real nice of you to take the time and do this for me. I was working on this all day yesterday and this morning and I just saw your response. It turns out I got this working this morning and I had to move the  if ($_SERVER['REQUEST_METHOD'] == 'POST' code to another file and I had to set the $schema variable total field to ->total('total'); // This needs to be 'total'.  I have attached all my files below. So the page now works as it is supposed to.

    I would like to make a recommendation, I am a hardcore back end developer and we want to use Kendo UI PHP code for our projects so we don't have to worry about all details of pretty front end development. Since you and everyone at Kendo UI have recently put up the PHP code it would be great if you guys could put up documentation describing all the PHP code since currently all the documentation is for JavaScript/jQuery. I want to stick with all of Kendo UI's PHP code  for development.

    Thank you very much for all you help Vladimir.

    Have a great weekend.

    Christian
  13. Christian
    Christian avatar
    15 posts
    Member since:
    Mar 2013

    Posted 12 Apr 2013 Link to this post

    Hello Vladimir,

    I have another issue as I forgot to ask earlier, the delete buttons are not showing up for each row of data.

    What do I need to do to turn on the delete button?

    Thank you.

    Christian
  14. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 15 Apr 2013 Link to this post

    Hi Christian,

     
    Your last question is not related to the original topic of this support conversation, so please submit a new support ticket / forum post for it. In this way you can be sure that your query will reach the corresponding staff member in time and will be answered faster and accurately.

    Kind Regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET AJAX banner