Browse Source

Supports items field to have only 1 item #283

pull/335/head
Alper Ebicoglu 8 years ago
parent
commit
5acbc64499
  1. 64
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js

64
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js

@ -2,11 +2,47 @@
(function ($) { (function ($) {
/************************************************************************ /************************************************************************
* RECORD-ACTIONS extension for datatables * * RECORD-ACTIONS extension for datatables
---------------------------------------------------------------
* USAGE: element (creates the JQuery element and puts in the specified target)
{
targets: 0,
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());
})
},
},
---------------------------------------------------------------
* USAGE: items (create a list of items)
{
targets: 0,
rowAction:
{
text: 'My actions',
items:
[
{
text: "My first action",
visible: function () {
return true;
},
action: function (data) {
console.log(data.record);
}
}
]
}
},
*************************************************************************/ *************************************************************************/
var recordActions = function() { var recordActions = function () {
if (!$.fn.dataTableExt) { if (!$.fn.dataTableExt) {
return; return;
} }
@ -26,7 +62,7 @@
if (!$(this).closest('li').hasClass('disabled')) { if (!$(this).closest('li').hasClass('disabled')) {
if (fieldItem.confirmMessage) { if (fieldItem.confirmMessage) {
abp.message.confirm(fieldItem.confirmMessage({ record: record })) abp.message.confirm(fieldItem.confirmMessage({ record: record }))
.done(function(accepted) { .done(function (accepted) {
if (accepted) { if (accepted) {
fieldItem.action({ record: record }); fieldItem.action({ record: record });
} }
@ -110,16 +146,18 @@
}; };
var _createRowAction = function (record, field, tableInstance) { var _createRowAction = function (record, field, tableInstance) {
if (field.items && field.items.length > 1) { if (field.items && field.items.length > 0) {
return _createButtonDropdown(record, field, tableInstance); return _createButtonDropdown(record, field, tableInstance);
} else if (field.element) { } else if (field.element) {
var $singleActionButton = _createSingleButton(record, field); var $singleActionButton = _createSingleButton(record, field);
if ($singleActionButton != "") { if ($singleActionButton === "") {
return $singleActionButton.clone(true); return "";
} }
return $singleActionButton.clone(true);
} }
return ""; throw "Cannot create row action. Either set element or items fields!";
} }
var hideColumnWithoutRedraw = function (tableInstance, colIndex) { var hideColumnWithoutRedraw = function (tableInstance, colIndex) {
@ -185,15 +223,15 @@
}); });
}(); }();
/************************************************************************ /************************************************************************
* AJAX extension for datatables * * AJAX extension for datatables *
*************************************************************************/ *************************************************************************/
var ajaxActions = function() { var ajaxActions = function () {
var datatables = abp.utils.createNamespace(abp, 'libs.datatables'); var datatables = abp.utils.createNamespace(abp, 'libs.datatables');
datatables.createAjax = function(serverMethod, inputAction) { datatables.createAjax = function (serverMethod, inputAction) {
return function(requestData, callback, settings) { return function (requestData, callback, settings) {
var input = inputAction ? inputAction() : {}; var input = inputAction ? inputAction() : {};
//Paging //Paging
@ -216,7 +254,7 @@
} }
if (callback) { if (callback) {
serverMethod(input).then(function(result) { serverMethod(input).then(function (result) {
callback({ callback({
recordsTotal: result.totalCount, recordsTotal: result.totalCount,
recordsFiltered: result.totalCount, recordsFiltered: result.totalCount,

Loading…
Cancel
Save