Jtable的问题

时间:2015-07-22 08:42:56

标签: php jquery jtable

有人知道JTable吗?我试图用这个插件创建一个specfici表但是我找不到正确的方法。我下载了示例并根据我的需要进行了修改。但在更改代码后,我只在浏览器中显示空白页。

有人可以向我解释错误/是什么?

index.php

<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jTable
        $('#PeopleTableContainer').jtable({
            title: 'Table of people',
            paging: true,
            pageSize: 50,
            sorting: true,
            defaultSorting: 'Name ASC',
            actions: {
                listAction: 'PersonActionsPagedSorted.php?action=list',
                createAction: 'PersonActionsPagedSorted.php?action=create',
                updateAction: 'PersonActionsPagedSorted.php?action=update',
                deleteAction: 'PersonActionsPagedSorted.php?action=delete'
            },
            fields: {
                    PersonId: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false,
                    width: '5%',
                },
                    Fecha: {
                    title: 'Fecha',
                    width: '10%',
                    type: 'date',
                }
                    Nombre: {
                    title: 'Nombre',
                    width: '10%',
                    options: { '1': 'Option1', '2': 'Option2', '3': 'Option3','4': 'Option4' }

                },
                    Turno: {
                    title: 'Turno',
                    width: '10%',
                    options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
                },
                    Info: {
                    title: 'Info',
                    width: '45%',
                    type: 'textarea'
                },
                    Estado: {
                    title: 'Estado',
                    width: '10%',
                    options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
                },
                    Criticidad: {
                    title: 'Criticidad',
                    width: '10%',
                    options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
                },

            }
        });

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

    });

</script>

PersonActionsPagedSorted.php

<?php

try
{
    //Open database connection
    $con = mysql_connect("localhost","root","");
    mysql_select_db("jtabletestdb", $con);

    //Getting records (listAction)
    if($_GET["action"] == "list")
    {
        //Get record count
        $result = mysql_query("SELECT COUNT(*) AS RecordCount FROM people;");
        $row = mysql_fetch_array($result);
        $recordCount = $row['RecordCount'];

        //Get records from database
        $result = mysql_query("SELECT * FROM people ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");

        //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);
    }
    //Creating a new record (createAction)
    else if($_GET["action"] == "create")
    {
        //Insert record into database
        $result = mysql_query("INSERT INTO people(Fecha, Nombre, Turno, Info, Estado, Criticidad) VALUES('" . $_POST["Fecha"] . "', '" . $_POST["Nombre"] . "','" . $_POST["Turno"] . "', '" . $_POST["Info"] . "','" . $_POST["Estado"] . "', '" . $_POST["Criticidad"] . ";");

        //Get last inserted record (to return to jTable)
        $result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
        $row = mysql_fetch_array($result);

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        $jTableResult['Record'] = $row;
        print json_encode($jTableResult);
    }
    //Updating a record (updateAction)
    else if($_GET["action"] == "update")
    {
        //Update record in database
        $result = mysql_query("UPDATE people SET Fecha = '" . $_POST["Fecha"] . "', Nombre = '" . $_POST["Nombre"] . "', Turno = '" . $_POST["Turno"] . "', Info = '" . $_POST["Info"] . "',Estado ='" . $_POST["Estado"] . "', Criticidad = '" . $_POST["Criticidad"]. "' WHERE PersonId = " . $_POST["PersonId"] . ";");

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        print json_encode($jTableResult);
    }
    //Deleting a record (deleteAction)
    else if($_GET["action"] == "delete")
    {
        //Delete from database
        $result = mysql_query("DELETE FROM people WHERE PersonId = " . $_POST["PersonId"] . ";");

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        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);
}

?>

如果你想知道,在这个世界上我是非常新手,我想答案很简单。

0 个答案:

没有答案