volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

Problem with child tables #304

Open asbppxp opened 11 years ago

asbppxp commented 11 years ago

I have successfully created the master table but it has an error while opening the child table. I don't know where is the error occurs. The second question Where and how can I find the JSON result? pro

    $(document).ready(function () {

        //Prepare jTable
        $('#CommentTableContainer').jtable({
            title: 'Table of Profeessor',
            paging: true,
            pageSize: 20,
            sorting: true,
            defaultSorting: 'firstName ASC',
    //openChildAsAccordion: true, //Enable this line to show child tabes as accordion style
            actions: {
                listAction: 'ProfessorActionsPagedSorted?action=listProfessor'
            },
            fields: {
                professorID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
      ProfessorComment: {
        title: '',
        width: '1%',
        sorting: false,
        edit: false,
        create: false,
        listClass: 'child-opener-image-column',
        display: function (professor) {
          //Create an image that will be used to open child table
          var $img = $('<img class="child-opener-image" src="../images/list_metro.png" title="Edit Professor Comment" />');
          //Open child table when user clicks the image
          $img.click(function () {
            $('#CommentTableContainer').jtable('openChildTable',
              $img.closest('tr'), //Parent row
              {
                title: professor.record.LastName + ' ' + professor.record.firstName + ' - Professor Comment',
                sorting: true,
                actions: {
                  listAction: 'ProfessorCommentActionsPagedSorted?professorID=' + professor.record.professorID
                },
                fields: {
                  professorCommentID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                  },
                  date: {
                    title: 'Date',
                    width: '30%',
                    type: 'date',
                    displayFormat: 'yy-mm-dd'
                  },
                  comment: {
                    title: 'Comment',
                    width: '10%'
                  }
                }
            }, function (data) { //opened handler
                data.childTable.jtable('load');
            });
          });
          //Return image to show on the person row
          return $img;
        }
      },
                firstName: {
                    title: 'First Name',
                    width: '15%',
                },
                LastName: {
                    title: 'Last Name',
                    width: '15%'
                },
                department: {
                    title: 'Deprtment',
                    width: '10%'
                },
                schoolName: {
                    title: 'School Name',
                    width: '30%'
                }
            }
        });

        //Load person list from server
        $('#CommentTableContainer').jtable('load');

    });

ProfessorCommentActionsPagedSorted.php <?php try { //Open database connection $con = mysql_connect("localhost","root",""); mysql_select_db("abcdef", $con);

//Get record count $result = mysql_query("SELECT COUNT(*) AS RecordCount FROM professorComment WHERE professorID = " . $_GET["professorID"] . ";"); $row = mysql_fetch_array($result); $recordCount = $row['RecordCount'];

//Get records from database $result = mysql_query("SELECT * FROM professorComment pc, professor p, user u WHERE p.professorID = pc.professorID AND u.userID = pc.userID AND p.professorID = " . $_GET["professorID"] . ";");

//Add all records to an array $rows = array(); while($row = mysql_fetch_array($result)) { $rows[] = $row; }

//Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; $jTableResult['TotalRecordCount'] = $recordCount; $jTableResult['Records'] = $rows; print json_encode($jTableResult);

//Close database connection
mysql_close($con);

} catch(Exception $ex) { //Return error message $jTableResult = array(); $jTableResult['Result'] = "ERROR"; $jTableResult['Message'] = $ex->getMessage(); print json_encode($jTableResult); } ?>

eirazabal commented 11 years ago

Cambiar esta línea: listAction: 'ProfessorCommentActionsPagedSorted?professorID=' + professor.record.professorID Por esta: listAction: 'ProfessorCommentActionsPagedSorted.php?professorID=' + professor.record.professorID