S M Abrar Jahin
S M Abrar Jahin

Reputation: 14578

jQuery DataTables - Custom Column Visiblity

I like to use jQuery DataTable Plugin and want to create something like this-

one

And when anyone click on "Column visibility" button, they will see like this-

www

But I don't like to have Global search Button and Pagination on top (because I have already a pagination in the bottom).

I only want that button.

So, what I have done is -

$(document).ready(function()
{
var dataTable =  $('#employee-grid').DataTable(
{
    processing: true,
    serverSide: true,
    //ajax: "employee-grid-data.php", // json datasource for AJAX Data

    "ajax":
    {
        "url": "employee-grid-data.php",
        //"type": 'POST',
        "data": function ( d )              //Sending Custom Data for manupulating with elements out of the table
                {
                    d.myKey = "myValue";
                    // d.custom = $('#myInput').val();
                    // etc
                },
    },

    //"pagingType": "full_numbers", //Adding Last and First in Pagination
    stateSave: true,
    "language":{                    //Custom Message Setting
                    "lengthMenu": "Display _MENU_ records per page",    //Customizing menu Text
                    "zeroRecords": "Nothing found - sorry",             //Customizing zero record text - filtered
                    "info": "Showing page _PAGE_ of _PAGES_",           //Customizing showing record no
                    "infoEmpty": "No records available",                //Customizing zero record message - base
                    "infoFiltered": "(filtered from _MAX_ total records)"   //Customizing filtered message
                },
    "lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],        //For customizing number of data sets per page

    dom: 'l<"toolbar">frtip Bfrtip',        //"Bfrtip" is for column visiblity

    initComplete:   function()  //Adding Custom button in Tools
                    {
                        $("div.toolbar").html('<button type="button" onclick="addNewEntry()">Add a New Record</button>');
                    },
    buttons:    [                   //Column Visiblity Buttons
                    {
                        extend: 'colvis',
                        collectionLayout: 'fixed three-column',
                        postfixButtons: [ 'colvisRestore' ]
                    }
                ],
});
});

More Preciously-

    dom: 'l<"toolbar">frtip Bfrtip',
    buttons:    [                   //Column Visiblity Buttons
                    {
                        extend: 'colvis',
                        collectionLayout: 'fixed three-column',
                        postfixButtons: [ 'colvisRestore' ]
                    }
                ],

But I am finding something like this-

asd

So, I want only Green Round and not Red Round.

What have I done wrong?

Upvotes: 2

Views: 4108

Answers (2)

Gyrocode.com
Gyrocode.com

Reputation: 58860

SOLUTION

Option dom can be a little confusing at first, but simply put, each letter in it is a DataTables feature. Also order of the letters describe their positioning on the page.

  • B - Buttons,
  • f - filtering input
  • r - processing display element
  • t - table
  • i - informational panel
  • p - pagination control

There are other letters and HTML markup supported. See dom option and Buttons - dom parameter pages for more information.

Use the code below:

var dataTable =  $('#employee-grid').DataTable({
    // ... skipped ... 
    dom: 'Brtip',        
    buttons: [
       {
          extend: 'colvis',
          collectionLayout: 'fixed three-column',
          postfixButtons: [ 'colvisRestore' ]
       }
    ]
});

DEMO

See this jsFiddle for code and demonstration.

Upvotes: 6

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

You need to add dom option of dataTable while initializing as below:

$('#example').DataTable( {
        "dom": '<"top"i>rt<"bottom"flp><"clear">'
});

You can see Source/Demo here

More Precise explanation

Upvotes: 2

Related Questions