Search code examples
symfonysortingtemplatesdatatableadapt

Modify Bootstrap DataTable


I used an example of bootstrap datatable to have a sortable table on my symfony project. I use datatables.net

With this javascript code :

$(document).ready(function() {
    $('#datatable').DataTable();
} );

And my table in HTML :

<table id="datatable" class="table table-striped">
 <thead>
    <tr>...

The only problem is that I don't want all my columns to be sortable (some columns only contain a checkbox or a button for example). Moreover with this table and this javascript code I automatically have a search bar as well as Previous Next buttons and other options that appear automatically. I would like to be able to modify this default template by removing all these options that I don't need. Do you have an idea how to adapt this datatable?

Thanks in advance


Solution

  • You should read documentation for datatables. https://datatables.net/extensions/rowreorder/examples/initialisation/restrictedOrdering.html

    Example:

    // add class reorder on column, that you want to order
    $(document).ready(function() {
        var table = $('#example').DataTable( {
            rowReorder: true,
            columnDefs: [
                { orderable: true, className: 'reorder', targets: 0 },
                { orderable: false, targets: '_all' }
            ]
        } );
    } );