Selected row remove function is not working if i assign data to data- table at server side.

Selected row remove function is not working if i assign data to data- table at server side.

Below remove functionality is not working if i assign data to data- table at server side( MVC controller file). if assign data at client ens in HTML file it is working fine. Please guide me on this?

table.rows( '.selected' ) .remove().draw();

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,922Questions: 26Answers: 5,067
    Answer ✓

    With server side processing you will need to remove the rows from your Database. Otherwise on each draw the table is refreshed from your server script/DB and the row appears to return.

    Kevin

  • raji.godugula@gmail.comraji.godugula@gmail.com Posts: 5Questions: 4Answers: 0

    Got you. Thanks.

  • chessGuru64chessGuru64 Posts: 79Questions: 18Answers: 1
    edited September 2018

    I am having a similar issue. Do you still use this code?
    columnDefs: [{
    targets: -1,
    defaultContent: '<button type="button" class="delete_btn" data-id="<?php echo "";?>">Delete</button> <button type="button" class="edit_btn">Edit</button>'
    }],

    The problem is labeling each delete button with a data-id without using a while loop?

  • kthorngrenkthorngren Posts: 21,922Questions: 26Answers: 5,067

    If you want to add an ID to your buttons I think you would be better of using columns.render. Something like this example:
    http://live.datatables.net/qemodapi/1/edit

    BTW, this is a different question than the original post.

    Kevin

  • MahikumarMahikumar Posts: 1Questions: 0Answers: 0

    <!DOCTYPE html>
    <html>
    <head>
    <title>New View Data</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

    </head>
    <body>
    <form class="">
    <table id="test" class="table-hover table-bordered" style="width:100%">
    <h1 align="center">View DataDetils Of Employees</h1>
    <thead>
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Email</th>
    <th>Password</th>
    <th>CPassword</th>
    <th>Language</th>
    <th>Role</th>
    <th>Salary</th>
    <th>Gender</th>
    <th>Number</th>
    <th>Address</th>
    <th>Photo</th>

                </tr>
            </thead>
        </table>
    
    </form>
    

    </body>
    </html>

    $(document).ready(function() { $('#test').DataTable( { 'processing':true, 'serverSide':true, 'ajax':'getdata.php' }); });

    =================================================================

    <?php

    //include_once('db.php');

    $db=array(
    'host'=>'localhost',
    'user'=>'root',
    'pass'=>'',
    'db' =>'new_emp_details'
    );

    $table='emp_main';
    
    
    //$table ="select * from emp_main" ;
    
    $primaryKey='emp_id';
    
    $columns=array(
                    array('db' =>'emp_id'     ,     'dt' => 0),
                    array('db'=>'emp_name'    ,     'dt' => 1),
                    array('db'=>'emp_email'   ,     'dt' => 2),
                    array('db'=>'emp_pass'    ,     'dt' => 3),
                    array('db'=>'emp_cpass'   ,     'dt' => 4),
                    array('db'=>'emp_lang'    ,     'dt' => 5),
                    array('db'=>'emp_roll'    ,     'dt' => 6),
                    array('db'=>'emp_salary'  ,     'dt' => 7),
                    array('db'=>'emp_gender'  ,     'dt' => 8),
                    array('db'=>'emp_number'  ,     'dt' => 9),
                    array('db'=>'emp_address' ,     'dt' => 10),
                    array('db'=>'emp_photo'   ,     'dt' => 11),
    
    
                  );
    
    
            require('ssp.class.php');
    
            echo json_encode
            (       
                SSP::simple( $_GET, $db, $table, $primaryKey, $columns)
            );
    
    <?php > ?>

    How to delete record from database using server side processing datatables

This discussion has been closed.