2

Is it possible to add more drop down or other html elements to the Datatable after the default

Display "5" record

I want to add more drop down to my DataTable between the Default one and the Search Bar which is provided by default.

I have gone through sDom but I am not able to understand the syntax.

Thanks in advance.

1 Answer 1

7

You can insert an element <div> between the length menu and the filter box this way :

var table = $('#example').DataTable({
   dom : 'l<"#add">frtip'
}) 

'lfrtip' is the default dom string, so you basically just add an <div id="#add"> to the existing layout. It is adviceable to style #add, especially setting the display type to inline-block so it not break the elements down under :

#add {
  display: inline-block;
  padding-left: 30px;
  float: left;
}

Now you can add <select>'s (or whatever) to the #add element the plain jQuery way :

//insert a label
$('<label/>').text('my dropdown').appendTo('#add')

//insert the select and some options
$select = $('<select/>').appendTo('#add')
$('<option/>').val('1').text('option #1').appendTo($select);
$('<option/>').val('2').text('option #2').appendTo($select);
$('<option/>').val('3').text('option #3').appendTo($select);

demo -> http://jsfiddle.net/ahqbf35w/

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much sir for your response and answer.
how to add another element to the div?
@SapneshNaik, you can do it the exact same way; have added an additional <input> with an ID here -> jsfiddle.net/ahqbf35w/22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.