Reduced repeating same fields #283

From now on, no need to set targets field of columnDefs and some fields of rowAction column (targets,data,orderable,autoWidth,defaultContent)...

Example usage:

var _dataTable = _$table.DataTable(abp.libs.datatables.normalizeConfiguration({
            order: [[1, "asc"]],
            ajax: abp.libs.datatables.createAjax(_identityUserAppService.getList),
            columnDefs: [
                {
                    rowAction: {
                        element: $("<button/>")
                            .addClass("btn btn-primary btn-sm m-btn--icon")
                            .text("My button")
                            .prepend($("<i/>").addClass("la la-sign-in"))
                            .click(function () {
                                console.log($(this).data());
                            })
                    },

                    rowAction1: {
                        items:
                            [
                                {
                                    text: "ITEM#1",
                                    action: function (data) {
                                        _editModal.open({
                                            id: data.record.id
                                        });
                                    }
                                },
                                {
                                    text: "ITEM#2",
                                    action: function (data) {
                                        _editModal.open({
                                            id: data.record.id
                                        });
                                    }
                                },
                                {
                                    text: "ITEM#3",
                                    visible: function (data) {
                                        return true;
                                    },
                                    action: function (data) {
                                        _editModal.open({
                                            id: data.record.id
                                        });
                                    }
                                },
                                {
                                    text: "ITEM#4",
                                    visible: function (data) {
                                        return true;
                                    },
                                    action: function (data) {
                                        _editModal.open({
                                            id: data.record.id
                                        });
                                    }
                                }
                            ]
                    }
                },
                {
                    data: "userName"
                },
                {
                    data: "email"
                },
                {
                    data: "phoneNumber"
                }
            ]
        }));
pull/335/head
Alper Ebicoglu 7 years ago
parent 7ff1d809c8
commit 98d53dfebf

@ -5,9 +5,9 @@
/************************************************************************
* RECORD-ACTIONS extension for datatables
---------------------------------------------------------------
* USAGE: element (creates the JQuery element)
* SINGLE BUTTON USAGE (creates the given JQuery element)
{
targets: 0,
targets: 0, //optional
rowAction:
{
element: $("<button/>")
@ -21,19 +21,19 @@
},
---------------------------------------------------------------
* USAGE: items (create a list of items)
* LIST OF ITEMS USAGE
{
targets: 0,
targets: 0, //optional
rowAction:
{
text: 'My actions',
icon: 'bolt' //see fa icon set https://fontawesome.com/v4.7.0/icons/
text: 'My actions', //optional. default value: Actions
icon: 'bolt' //optional. default value: cog. See fa icon set https://fontawesome.com/v4.7.0/icons/
items:
[
{
text: "My first action",
icon: "thumbs-o-down",
visible: true // or you can use functions eg: function(){ return true/false;} ,
text: "My first action", //mandatory
icon: "thumbs-o-down", //optional.
visible: true //optional. default value: true. Accepts boolean returning function too. Eg: function(){ return true/false;} ,
action: function (data) {
console.log(data.record);
}
@ -271,9 +271,9 @@
/************************************************************************
* AJAX extension for datatables *
*************************************************************************/
var ajaxActions = function () {
var datatables = abp.utils.createNamespace(abp, 'libs.datatables');
var datatables = abp.utils.createNamespace(abp, 'libs.datatables');
var ajaxActions = function () {
datatables.createAjax = function (serverMethod, inputAction) {
return function (requestData, callback, settings) {
var input = inputAction ? inputAction() : {};
@ -310,4 +310,37 @@
}
}();
/************************************************************************
* Configuration/Options normalizer for datatables *
*************************************************************************/
var optionNormalizer = function () {
var customizeRowActionColumn = function(column) {
column.data = null;
column.orderable = false;
column.defaultContent = "";
if (column.autoWidth === undefined) {
column.autoWidth = false;
}
};
datatables.normalizeConfiguration = function (configuration) {
for (var i = 0; i < configuration.columnDefs.length; i++) {
var column = configuration.columnDefs[i];
if (!column.targets) {
column.targets = i;
}
if (column.rowAction) {
customizeRowActionColumn(column);
}
}
return configuration;
}
}();
})(jQuery);
Loading…
Cancel
Save