0

我正在使用带有 PHP 语言的 jTable,下面是带有数据的 jTable 在此处输入图像描述

我尝试过的jTable的代码...

<script type="text/javascript">

    $(document).ready(function () {

        $('#StudentTableContainer').jtable({
            title: 'The Student List',
            paging: true, //Enable paging
            pageSize: 10, //Set page size (default: 10)
            sorting: true, //Enable sorting
            defaultSorting: 'Name ASC', //Set default sorting
            actions: {
                listAction: '/Demo/StudentList',
                deleteAction: '/Demo/DeleteStudent',
                updateAction: '/Demo/UpdateStudent',
                createAction: '/Demo/CreateStudent'
            },
            fields: {
                StudentId: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                Name: {
                    title: 'Name',
                    width: '23%'
                },
                EmailAddress: {
                    title: 'Email address',
                    list: false
                },
                Password: {
                    title: 'User Password',
                    type: 'password',
                    list: false
                },
                Gender: {
                    title: 'Gender',
                    width: '13%',
                    options: { 'M': 'Male', 'F': 'Female' }
                },
                CityId: {
                    title: 'City',
                    width: '12%',
                    options: '/Demo/GetCityOptions'
                },
                BirthDate: {
                    title: 'Birth date',
                    width: '15%',
                    type: 'date',
                    displayFormat: 'yy-mm-dd'
                },
                Education: {
                    title: 'Education',
                    list: false,
                    type: 'radiobutton',
                    options: { '1': 'Primary school',
                               '2': 'High school',
                               '3': 'University' }
                },
                About: {
                    title: 'About this person',
                    type: 'textarea',
                    list: false
                },
                IsActive: {
                    title: 'Status',
                    width: '12%',
                    type: 'checkbox',
                    values: { 'false': 'Passive', 'true': 'Active' },
                    defaultValue: 'true'
                },
                RecordDate: {
                    title: 'Record date',
                    width: '15%',
                    type: 'date',
                    displayFormat: 'dd.mm.yy',
                    create: false,
                    edit: false,
                    sorting: false //This column is not sortable!
                }
            }
        });

        //Load student list from server
        $('#StudentTableContainer').jtable('load');
    });

</script>

jTable 对我来说一切正常,但我想在列add one more colomn named "Sr No"之前使用 1、2、3 等Name数字。

期望的输出.. 在此处输入图像描述

对于 jTable 参考:

编辑:

/Demo/StudentList 方法中的代码..

                    //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);
4

1 回答 1

1

我最好的猜测:把它放在'name'字段之前

srNo: {
  title: 'Sr',
},

srNo在服务中填写您的json对象/Demo/StudentList..您可以在循环中使用索引

在你的 PHP 代码中试试这个:

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

交叉手指!

于 2013-09-09T02:28:27.530 回答