Put a drop down to sort in the place of the seach box

Put a drop down to sort in the place of the seach box

shaggy73shaggy73 Posts: 5Questions: 2Answers: 1

I am trying to put drop down box to change the table sortig there where usually the searchbox is.

So far I came up with this. I changed the dom to this:

"<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'<'dataTables_filter'>>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>";

which leads to an empty div with the class "datatables_filter" - thats the place where I want to put the drop down via javascript.

The I use the "draw" event. Inside the function for the "draw" event I do this (Article is the id of my table):

$('#Article th').each(function (i, item) {
if ($(this).data('orderable') === true) {
items.push("<option value='[" + i + ", asc]'>" + $(this).data('name') + "aufsteigend</option>");
items.push("<option value='[" + i + ", desc]'>" + $(this).data('name') + "absteigend</option>");
}
});
// this selector does not work
$('.dataTables_filter').html(html + items.join("") + "</select>");

Actually all works fine, except of putting the created html into the div with the class 'dataTables_filter'. It is simply not there. Looks like after the draw event the html is not yet there.

Any ideas how I can get this working?

This question has an accepted answers - jump to answer

Answers

  • shaggy73shaggy73 Posts: 5Questions: 2Answers: 1
    Answer ✓

    Well, I got it working on my own. What I actually did was

    First to create the data table

    $('#Article').DataTable({
                ajax: { "url": ajaxUrl, "type": ajaxType },
                language: { "url": languageFile },
                columnDefs: colConfig
            });
    

    And then to attach the event

    $('#Article').DataTable().on('draw', function() { dosomething };);
    

    If I do it fluently, it works

    $('#Article').DataTable({
                ajax: { "url": ajaxUrl, "type": ajaxType },
                language: { "url": languageFile },
                columnDefs: colConfig
            }).on('draw', function() { dosomething };);
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Thanks for posting back - good to hear you've got it working now.

    Allan

This discussion has been closed.