0

I am using jQuery DataTables to sort through table data and I want to customize the layout. Instead of the framework injecting the HTML elements, I just want to specify using IDs where they should be. This is my initialization:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('#results-table').dataTable({
            "sDom": 'fi'
        });
    });
</script>

That puts in both the search bar and the information text. I have already created an input that I want to use for the filter as well as a div for the information displayed. I just need the framework to insert the HTML into these elements instead of creating new ones.

3
  • Those elements do occur outside the table. Not sure what you're asking. Commented May 1, 2013 at 20:23
  • what do you mean "outside of the table"? they are outside of the <table> html Commented May 1, 2013 at 20:24
  • I apologize for being unclear there. What I mean is that when Datatables is initialized it creates three divs (wrapper, filter and info) around the <table>. I have already created an input that I want to use for the filter as well as a div for the information displayed. I just need the framework to insert the HTML into these elements instead of creating new ones. Commented May 1, 2013 at 20:41

1 Answer 1

1

Ok so this is how you add your own elements to the sDom (note that in my example, i am using jquery ui for styling, so i have to add ui elements)

 var oTable = $('#example').dataTable( {
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sDom": '<"ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-     helper-clearfix"l f <"dataTables_mylist"><"dataTables_dater"> r>t<"ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',

datatables_mylist and dataTables_dater are both element ids that I inject content into after load. You would need to use standard jQuery / DOM methods (i.e. appendChild) after DataTables has been initialised, it cannot grab an existing element and move it.

In my application, Mylist is a button that onclick applies a specific filter by userid so that i dont have to display a user column, and a user doesnt have to type in their userid in the search box

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

Comments

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.