Laravel-datatables: Setting up default

Created on 9 Feb 2016  路  4Comments  路  Source: yajra/laravel-datatables

I think it will be beneficial to define default parameter in config file. (Let me know if something similar to set default is already present).

->parameters([ 'order' => [[2, "desc"]], 'paging' => true, 'lengthChange' => true, 'searching' => true, 'searchDelay' => 2000, //ms 'ordering' => true, 'info' => true, 'autoWidth' => false, 'stateSave' => true, 'scrollX' => false, 'select' => ['style' => 'multi', 'selector' => 'input[type="checkbox"]:checkbox'], 'dom' => '<"row"<"col-sm-6"l><"col-sm-6"p>> <"row"<"col-sm-12"tr>><"row"<"col-sm-5"i><"col-sm-7"p>>', ])

Most helpful comment

On my opinion, the default should be set on a separate js file and this what I usually do.

 $.extend(true, DataTable.defaults, {
            "dom": "<'row'<'col-md-4 col-sm-12'<'pull-left'f>><'col-md-8 col-sm-12'<'table-group-actions pull-right'B>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>", // datatable layout
            "pagingType": "bootstrap_extended",
            "buttons": [],
            "renderer": "bootstrap",
            "deferRender": true,
            "autoWidth": false, // disable fixed width and enable fluid table
            "pageLength": 10, // default records per page
            "language": { // language settings
                "lengthMenu": "<span class='seperator'>|</span>View _MENU_ records ",
                "info": "<span class='seperator'>|</span>Found _TOTAL_ total records ",
                "infoEmpty": "No records found to show",
                "emptyTable": "No data available in table",
                "zeroRecords": "No matching records found",
                "search": "<i class='fa fa-search'></i>",
                "paginate": {
                    "previous": "Prev",
                    "next": "Next",
                    "last": "Last",
                    "first": "First",
                    "page": "Page",
                    "pageOf": "of"
                }
            }
        });

All 4 comments

On my opinion, the default should be set on a separate js file and this what I usually do.

 $.extend(true, DataTable.defaults, {
            "dom": "<'row'<'col-md-4 col-sm-12'<'pull-left'f>><'col-md-8 col-sm-12'<'table-group-actions pull-right'B>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>", // datatable layout
            "pagingType": "bootstrap_extended",
            "buttons": [],
            "renderer": "bootstrap",
            "deferRender": true,
            "autoWidth": false, // disable fixed width and enable fluid table
            "pageLength": 10, // default records per page
            "language": { // language settings
                "lengthMenu": "<span class='seperator'>|</span>View _MENU_ records ",
                "info": "<span class='seperator'>|</span>Found _TOTAL_ total records ",
                "infoEmpty": "No records found to show",
                "emptyTable": "No data available in table",
                "zeroRecords": "No matching records found",
                "search": "<i class='fa fa-search'></i>",
                "paginate": {
                    "previous": "Prev",
                    "next": "Next",
                    "last": "Last",
                    "first": "First",
                    "page": "Page",
                    "pageOf": "of"
                }
            }
        });

Yes, I recall this from before I was using yajra/laravel-datatables, this is the datatables way of defining the default options. Thanks for reminding this, I will use this approach for my project now.
With laravel-datatables in my opinion is more and more control is to be shifted from views to controllers. (That just my opinion :-) )

Thanks for the response and The great "laravel-datatables" package.

We can't really put all the js on the builder due to some limitations but will see if we can do that on future releases. :+1:

Thank you @yajra I've used in my project with AdminLte pt-BR

$.extend(true, jQuery.fn.dataTable.defaults, {
        "language": { // language settings
        "info": "<span class='seperator'>|</span>Encontrados _TOTAL_ registros ",
        "infoEmpty": "N茫o foram encontrados registros para exibi莽茫o.",
        "emptyTable": "Sem registros dispon铆veis para exibi莽茫o.",
        "zeroRecords": "N茫o foram encontrados registros.",
        "search": "<i class='fa fa-search'></i>",
        "paginate": {
            "previous": "Anterior",
            "next": "Pr贸ximo",
            "last": "脷ltimo",
            "first": "Primeiro",
            "page": "P谩gina",
            "pageOf": "de"
        }
    }
});
Was this page helpful?
0 / 5 - 0 ratings