Data table editor: How do use envelopeintable with custom query

Data table editor: How do use envelopeintable with custom query

iaminfantiaminfant Posts: 1Questions: 1Answers: 0

As suggested here https://editor.datatables.net/examples/styling/envelopeInTable.html , I tried to build a custom query php file.. But editor didn't work well. How can I achieve this.

My dataget.php file code is:

 $query ="SELECT * FROM customers ";  
        
         $result = mysqli_query($con, $query);
        
 while($row = $result->fetch_array(MYSQLI_ASSOC)){
  $columns["data"][] = $row ;
}

echo json_encode($columns);

I use dataget.php instead of staff.php

with libraries mentioned in https://editor.datatables.net/examples/styling/envelopeInTable.html ,

And My JS is

var editor; // use a global for the submit and return data rendering in the examples
 
$(document).ready(function() {
     // New record
    $('a.editor_create').on( 'click', function (e) {
        e.preventDefault();
 
        editor
            .title( 'Create new record' )
            .buttons( { "label": "Add", "fn": function () { editor.submit() } } )
            .create();
    } );
 
    // Edit record
    $('#example').on( 'click', 'a.editor_edit', function (e) {
        e.preventDefault();
 
        editor
            .title( 'Edit record' )
            .buttons( { "label": "Update", "fn": function () { editor.submit() } } )
            .edit( $(this).closest('tr') );
    } );
      // Delete a record
    $('#example').on( 'click', 'a.editor_remove', function (e) {
        e.preventDefault();
 
        editor
            .title( 'Edit record' )
            .message( "Are you sure you wish to delete this row?" )
            .buttons( { "label": "Delete", "fn": function () { editor.submit() } } )
            .remove( $(this).closest('tr') );
    } );
    //Load
    $('#example').DataTable( {
        ajax: "dataget.php",
        columns: [
             { data: "CompanyName" },
            { data: "ContactName" },
            { data: "ContactTitle" },
            { data: "Address" },
            {
                data: null,
                className: "center",
                defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
            }
        ]
    } );
});

    

It only fetch the records..But can't edit or delete?

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @iaminfant ,

    Can you give more information, please. When you say it isn't working, are you seeing errors, on the client or server? Is the data being passed to the server? Is it being updated in the DB but not in the table? Could you also link to your page, as that would help understand what's going on?

    Cheers,

    Colin

This discussion has been closed.