Skip to content

Multi Datatable with using only one model #1409

@jamesriady

Description

@jamesriady

This is My controller

        $languages = Language::where('IsActive', 1)->get();
        if($request->ajax()) {  
                $post = Post::where('LanguageID', $request->input('LanguageID')));
            return Datatables::of($post)
            ->addColumn('action', function($post){
                return '<a id="edit" class="btn btn-info" 
                                     href="post/' . $post->id . '/edit">
                                        <i class="glyphicon glyphicon-edit icon-white"></i>
                                        Edit
                                    </a>
                                    <button type="button" class="btn btn-danger"
                                     onclick="checkDelete('.$post->id.', this);" 
                                     data-token="{{ csrf_token() }}">
                                        <i class="glyphicon glyphicon-trash icon-white"></i>
                                        Delete
                                    </button>';
                                })
            ->make(true);
        } 
        return view('pages.back-end.lists.post')->with('languages', $languages);  

This is my view
https://i.stack.imgur.com/TbMHv.png

This is my yajra

  $('.tabPost').each(function(){
    var lang_id = $(this).attr('id');
    console.log(lang_id);
    var oTable = $("#data-post" + lang_id).DataTable({
      processing: true,
      serverSide: true,
      ajax:{
        url: "{{ url("post") }}",
        data: function(d) {
          d.LanguageID = lang_id
        }
      },
      columns: [
          { data: 'PostDate', name: 'PostDate'},
          { data: 'PostTitle', name: 'PostTitle' },
          { data: 'PostSlug', name: 'PostTitle' },
          { data: 'action', name: 'action'}
      ]
    });

    $('#'+lang_id).on('click', function(e){
      oTable.draw();
      e.preventDefault();
    });

  }); 

I want to make my table has tab panel.. So, if I choose tab with language id 1, then display all data with language id 1, if I choose tab with language id 2, then display all data with language 2. Can I do like that in Yajra?

System details

  • Operating System
  • PHP Version
  • Laravel Version
  • Laravel-Datatables Version

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions