Server-Side Example SSP Class Working (but adding edit/delete button issues)

Server-Side Example SSP Class Working (but adding edit/delete button issues)

chessGuru64chessGuru64 Posts: 3Questions: 1Answers: 0

Intro: I am doing a server-side datatable.net Jquery plug-in using json, ajax, and ssp.class.php. I have it working but attempting to make buttons that can edit and delete. I am able to do this without the plug-in (but for some reason am stumped currently).

Output Link: Sample Link:

Code:

       $(document).ready(function() {
            $('#example').DataTable( {
               // "pagingType": "scrolling",
                "processing": true,
                "serverSide": true,

                    "ajax": {
                        "url": "server.php",
                        "type": "POST"
                    },
             });

         }); 
        </script>
          <body>

        <table id="example" class="display" style="width:100%" class="table table-striped table-bordered table-hover table-condensed">
         <thead class="thead-inverse">
        <tr>
        <th><a class="column_sort" id="id" href="?order=id&sort=<?php echo $sort; ?>">
                ID
        </th>
        <th><a class="column_sort" id="first_name" data-order="<?php echo $sort;?>" href="?order=first_name&sort=<?php echo $sort; ?>">First Name </a>
        </th>
        <th><a class="column_sort" id="last_name" href="?order=last_name&sort=<?php echo $sort; ?>">Last Name
        </a>
        </th>
        <th><a class="column_sort" id="position" href="?order=position&sort=<?php echo $sort; ?>">Position
        </a>
        </th>
        <th class="hidden-xs"><a class="column_sort" id="date" href="?order=date&sort=<?php echo $sort; ?>">Date </a>
        </th>
        <th class="hidden-xs"><a class="column_sort" id="updated" href="?order=updated&sort=<?php echo $sort; ?>">Updated
        </a> </th>
        <th>Action</th>
        </thead> </tr>
                <tbody>

                </tbody>
            </table>
            </div>          
        <?php

        $orderby="";
        $sort="";
        $sort = isset($_GET['sort']) ? $_GET['sort'] : 'ASC';
        $sort = ($sort == 'ASC') ? 'DESC': 'ASC';

        $order  = array("first_name","last_name", "date", "position", "updated"); 
        $key     = array_search($sort, $order); 
        $orderby = $order[$key];
        $records = mysqli_query($con, "SELECT * FROM employees ORDER BY $orderby $sort");

        $data=array();
        while ($row = mysqli_fetch_array($records, MYSQLI_ASSOC)) { 
            $row['delete_button']='<button type="button" class="btn btn-warning">Delete</button>';
            $data[]=$row;
        }
        $requestData= $_REQUEST;

        $count=mysqli_query($con, "SELECT * FROM employees"); 
        $totalData= $count->num_rows;
        $totalFiltered=$totalData;

        $json_data = array(
                          "draw" => intval(isset($_GET['draw'])), 
                          "recordsTotal"    => intval( $totalData ), 
                          "recordsFiltered" => intval( $totalFiltered ),
                          "data"            => $data //How To Retrieve This Data
                         );

        echo json_encode($json_data);
        ?>

Error:
DataTables warning: table id=example - Requested unknown parameter '6' for row 0, column 6. For more information about this error, please see http://datatables.net/tn/4

Answers

  • chessGuru64chessGuru64 Posts: 3Questions: 1Answers: 0

    HERE IS SAMPLE LINK: https://databasetable-net.000webhostapp.com/ The one in the main post is the wrong link. I cannot edit, I think it has been after the 15min period. Sorry!

  • allanallan Posts: 47,045Questions: 1Answers: 6,628 Site admin

    The link says it is "sleeping". I'll try and get in a little while.

    Allan

  • chessGuru64chessGuru64 Posts: 3Questions: 1Answers: 0
    edited April 17

    Yes it sleeps for 1 hour at 3am eastern time. You either do not live in the USA or you up very early (ha). As of right now I have it on a free server temporarily. Sorry for the trouble.

  • allanallan Posts: 47,045Questions: 1Answers: 6,628 Site admin

    I'm in the UK :).

    Try adding something like:

    columnDefs: [ {
      targets: -1,
      defaultContent: 'Edit / Delete' // expand as needed
    } ]
    

    to your initialisation of the DataTable. This example shows that being done in an Editor context, but the same method will work for any.

    Allan

Sign In or Register to comment.