volosoft / jtable

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

Jtable Issue #1692

Open fahdsaeed opened 9 years ago

fahdsaeed commented 9 years ago

Hi,

I'm trying to use Jtable with SQL Server and now it has made me go crazy. I have tried every possible thing and the records just dont display on my web page. Here are snippets of code that i have on my files:

TableList.php

    <div class="container singleblog">
    <div id="PersonTableContainer"></div>

    <script type="text/javascript">

    $(document).ready(function () {
    $('#PersonTableContainer').jtable({
        title: 'Balls of Steel',
        actions: {
                listAction: 'PersonList.php?action=list',
                },
        fields: {
            tesId: {
                key: true,
                create: false,
                edit: false
            },
            testname: {
                title: 'Name',
                width: '40%'
            },
            testnumber: {
                title: 'Number',
                width: '20%',
                create: false,
                edit: false
                        }
                }
    });

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

    });

</script>

Here is my personlist.php

<?php try { $servername = "sethdemo.trapponline.local"; $connectioninfo = array("Database"=>"VMTest", "UID"=>"fsaeedtest", "PWD"=>"wordpass"); $conn = sqlsrv_connect( $serverName, $connectioninfo); //$_GET["action"] = "list";

if ($conn==false) { echo " unable to connect."; die (print_r(sqlsrv_errors(), true));

}

else { 
                $_GET["action"] == "list";
               // $testId = $_POST['tesId'];
                $sql = "select * from dbo.test";
                $result = sqlsrv_query($conn, $sql);                        
                $rows = array();
                while ($row = sqlsrv_fetch_array($result)) 
                {

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

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

?>

This is my head file

I have shared head just in case some people would like to know what version of JQuery and JQuery UI i'm using. Please help me as now i have given up since its not working.

fahdsaeed commented 9 years ago

I know this issue has been discussed time and again but i would appreciate if someone can help me

fahdsaeed commented 9 years ago

This is my JSON that i receive on personlist.php page

{"Result":"OK","Records":[{"0":1,"tesId":1,"1":"Matt","testname":"Matt","2":"603","testnumber":"603"},{"0":2,"tesId":2,"1":"David","testname":"David","2":"604","testnumber":"604"},{"0":3,"tesId":3,"1":"Fahd","testname":"Fahd","2":"605","testnumber":"605"}]}

alfonsor commented 9 years ago

In your JSON is not the property TotalRecordCount...