im trying to implement my custom loading in angular datatables. I checked the docs :https://l-lin.github.io/angular-datatables/#/overrideLoadingTpl, there suggest an implementation:
angular.module('showcase', ['datatables']).
factory('DTLoadingTemplate', dtLoadingTemplate);
function dtLoadingTemplate() {
return {
html: '<img src="images/loading.gif">'
};
}
So, in my custom Options i inject the loading in the option sLoadingRecords and sProcessing, but doesnt works.
.factory('myDTOptions', function (DTOptionsBuilder,DTLoadingTemplate) {
return {
option1: function(){
return DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(10)
.withBootstrap()
.withOption('responsive', true)
.withLanguage({
"sEmptyTable": "No hay información disponible",
"sInfo": "Mostrando _START_ a _END_ de _TOTAL_ entradas",
"sInfoEmpty": "Mostrando 0 a 0 de 0 entradas",
"sInfoFiltered": "(filtrada de _MAX_ entradas totales)",
"sInfoPostFix": "",
"sInfoThousands": ",",
"sLengthMenu": "Mostrando _MENU_ entradas",
"sLoadingRecords": DTLoadingTemplate,
"sProcessing": DTLoadingTemplate,,
"sSearch": "Buscar: ",
"sZeroRecords": "No se encuentra coincidencias en la búsqueda",
"oPaginate": {
//Dos opciones: https://github.com/DataTables/Plugins/issues/62
"sFirst": '<i class="fa fa-angle-double-left"></i>',
"sLast": '<i class="fa fa-angle-double-right"></i>',
"sNext": '<i class="fa fa-angle-right"></i>',
"sPrevious": '<i class="fa fa-angle-left"></i>'
},
"oAria": {
"sSortAscending": ": activar para ordenar columna ascendentemente",
"sSortDescending": ": activar para ordenar columna descendentemente"
}
})
/*
.withColVis()
.withColVisOption('aiExclude', [0,1,6,7,8])*/
}
I had the same problem; after investigating the source it turns out to be quite simple. datatables.options
should be injected as a dependency exactly as all the other dataTables features :
angular.module('myModule', [
'datatables',
'datatables.buttons',
'datatables.bootstrap',
'datatables.fixedheader',
...
'datatables.options', //<---
])
Then the DTDefaultOptions
service should be included as well (example) :
.controller('myCtrl', ['$scope', 'DTOptionsBuilder', 'DTDefaultOptions',
function ($scope, DTOptionsBuilder, DTDefaultOptions) {
Now the default <h3>Loading...</h3>
template can be changed by (example) :
DTDefaultOptions.setLoadingTemplate('<em>Fetching data</em> ...')
The Loading... element has nothing to do with dataTables language settings, but is angular dataTables own initialisation message. BTW this element can be styled through the CSS class .dt-loading
:
.dt-loading {
color: red;
}