PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 6, 2022

[FIXED] how to add custom action buttons in jquery datatable edit/delete

 September 06, 2022     ajax, datatable, jquery     No comments   

Issue

I tried adding the action buttons in my ajax datatable edit/delete but its not working. I tried adding it using data option but its messing up the ajax call here is the code

<script type="text/javascript">
                
    $(document).ready(function(){

       $(document).on("click" , "#add-stockin" , function(){

        window.location.href = './stockin.php';

     }); 
 
    var table = $('#table1').DataTable( {
        dom: "Bfrtip",
      ajax: {
        url : "http://localhost/cokeinventory/rest-api/api-search-stockin.php",
        dataSrc: "doc",
        
       
      },
      columns: [
        { data: 'stock_id'},
        { data: 'item_name'},
        { data: 'unit' },
        { data: 'stockin_qty' },
        { data: 'barcode_number' },
        { data: 'barcode_label' },
        { data: 'balquantity' },
        {data: "stock_id" , render : function ( data, type, row, meta ) {
              return type === 'display'  ?
                '<a href="" id='deletebtn';?>'+ data +'" >Delete<i class="fe fe-delete"></i></a>' :
                
            }},

      ],
    });

  });

    </script>

Solution

Below is the code to add custom action links to jQuery datatable:

Here please refer official documentation for the same: https://editor.datatables.net/examples/simple/inTableControls.html

$(document).ready(function(){
        $(document).on("click" , "#add-stockin" , function(){
            window.location.href = './stockin.php';
        });

        var table = $('#table1').DataTable( {
            dom: "Bfrtip",
            ajax: {
                url : "http://localhost/cokeinventory/rest-api/api-search-stockin.php",
                dataSrc: "doc",
            },
            columns: [
                { data: 'stock_id'},
                { data: 'item_name'},
                { data: 'unit' },
                { data: 'stockin_qty' },
                { data: 'barcode_number' },
                { data: 'barcode_label' },
                { data: 'balquantity' },
                {
                    data: null,
                    className: "dt-center editor-delete",
                    orderable: false,
                    "mRender" : function ( data, type, row ) {
                        return '<a href="" id="deletebtn_' + data.stock_id+'" >Delete <i class="fe fe-delete"></i></a>';
                    }
                }

            ],
        });

    });


Answered By - Aniket Panchal
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing