zeerobug
7/5/2017 - 1:37 PM

datatables.js

                /* Initialize datatables */
                datatable = $('#dt_users').dataTable({
                        // Tabletools options:
                        //   https://datatables.net/extensions/tabletools/button_options
                        fixedHeader: true,
                        processing: true,
                        serverSide: true,
                        stateSave: true,
                        ajax: {
                                url    : '/api/users',
                                data   : function(d) {
                                        var client_id = $('#selectClient').val();
                                        if(client_id == 0) {
                                                delete d.client_id;
                                        } else {
                                                d.client_id = client_id;
                                        }
                                },
                                dataSrc: function(json) {
                                        json.data.forEach(function(row, i) {
                                                row.DT_RowId = 'rowId_' + row.DT_RowId;
                                                html = swig.render($('#actionColumn').html(), {locals: row});
                                                row.actions = html;
                                                row.activeHTML = row.active == 1 ? 'Yes' : 'No';
                                        });
                                        return json.data;
                                }
                        },

                        sDom: "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'T>r>"+
                                        "t"+
                                        "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
                oTableTools: {
                         aButtons: [
                     "copy",
                     "csv",
                     "xls",
                        {
                            sExtends: "pdf",
                            sTitle: "SmartAdmin_PDF",
                            sPdfMessage: "SmartAdmin PDF Export",
                            sPdfSize: "letter"
                        },
                        {
                        sExtends: "print",
                        sMessage: "Generated by SmartAdmin <i>(press Esc to close)</i>"
                        }
                     ],
                    sSwfPath: "/js/plugins/datatables/swf/copy_csv_xls_pdf.swf"
                },
                        autoWidth : true,
                        preDrawCallback : function() {
                        },
                        drawCallback : function(oSettings) {
                        },
                        fnCreatedRow: function( nRow, aData, iDataIndex ) {
                        },
                        fnRowCallback: function( nRow, aData ) {
                                var $nRow = $(nRow); // cache the row wrapped up in jQuery
                                if(aData.deleted_at) {
                                        $nRow.addClass('warning'); // user is inactive
                                } else if(!!!+aData.active) {
                                        $nRow.addClass('danger'); // user is deleted
                                }
                                return nRow;
                        },
                        columns: [
                                { "data": "client.company" },
                                { "data": "username" },
                                { "data": "email" },
                                { "data": "firstname"},
                                { "data": "timezone.abbreviation" },
                                { "data": "language.name" },
                                { "data": "activeHTML"},
                                { "data": "actions"}
                        ],
                        columnDefs: [
                                { "min-width": "110px", "targets": 3 },
                        ]
                });
                /* END TABLETOOLS */
        };