Friday, January 28, 2022

How to add dynamic id to data-tables tr with ajaxify content in Laravel?

add dynamic id to data-tables tr ajaxify content in Laravel

Hello to all, welcome to In this post, I will tell you, How to add dynamic id to data-tables tr ajaxify content in Laravel?  Laravel is one of the top php mvc framework

Datatables are the powerful jquery plug-in and it is used to create table listing with sorting and searching and many more functionality. I personally like data-tables very much because it is well-mannered listing of content in table structure.

In this post, I will let you, how to add id to data-tables tr row so we can do more with that content.

In my last post, I told  data-tables with ajaxify content and below is that post link:

DT_RowId will add it to data-tables tr.




First, we will do code in laravel controller:

public function Getdata(Request $request)
    $list = DB::table('users')
            ->select(('id as DT_RowId','name','email','telephone','updatedat')

        return response()->json([
            'data' => $list


  Second, we will do code in laravel route:

Route::match(['get','post'],'/suppliers/getsupplier', 'InventorySupplierController@GetSupplier')->middleware('ajax');

 Third, finally we will do code in laravel view:

<table id="clientsTable" class="table display responsive nowrap">
                        <th>Updated at</th>

                    <tr data-toggle="modal" data-target="#modaldemo5">
      <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
  var cTable = $('#clientsTable').DataTable({
        searching: true,
        responsive: true,
        bLengthChange: false,
        "autoWidth": false,
        language: {
         searchPlaceholder: 'Search by name..',
         sSearch: '',
        "ajax": {
            "url": '/getdata',
             dataSrc: 'data',
        columns: [
                { data: 'name' },
                { data: 'email' },
                { data: 'telephone' },
                { data: 'updatedat' }


There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.