How to add custom dropdown inside the datatable pl

2019-06-25 13:56发布

问题:

I'm using DataTable 1.10+ and I need to display a dynamic dropdown inside the DataTable jquery plugin which should be aligned properly in the top in between the paging and search filter.

I embedded some html after DataTable initialization inside the table to display it(see demo below). But is there any better version of doing this which will be helpful in creating dropdown with dynamic values.

Here's a demo of what I've tried and want looks like, JSFiddle Demo

var html =  '<div id="custome_dropdown"><div id="example_dropdown" class="dataTables_length"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show</label><select id="filter"><option value="firefox">firefox</option><option value="mozilla">mozilla</option></select></div></div>';

$(html).insertAfter("#example_wrapper #example_length");