I'm using the famous angular-datatables plugin that combines Jquery Datatables with Angular.
I just learned how to use a factory to fetch data from a JSON file.
My question is: Could you use a factory on angular-datatables to use it as source ?
EDITED (06/22/2016)
This is what I have tried:
//Factory que traerá la data Global
statisticsModule.factory('globalFactory', function($rootScope, $http){
var globalFactory = {};
globalFactory.getUrl = function(){
return $http.get('../statistics/php/config_statistics.json');
};
return globalFactory;
});
//Controller / Controlador
statisticsModule.controller("dataController", dataController); //Fin controlador
function dataController($scope, $http, globalFactory, DTOptionsBuilder, DTColumnBuilder){
//Promise con el factory
globalFactory.getUrl().then(function(response){
//Obtener data
var urlGlobal = response.data;
//Filtrar data. arrayReportBD : Arreglo con las URL de los reportes
var deserialize = angular.fromJson(urlGlobal.config.graph_conf_array.arrayReportBD);
//Data Distribución de Estatus
var urlStatus = deserialize[0];
//Obtener data de Distribución de Estatus
$http.get(urlStatus).success(function(data){
console.log(data);
var vm = this;
vm.dtOptions = DTOptionsBuilder.fromSource(data)
.withDOM('lfrtip')
.withPaginationType('full_numbers')
.withLanguage({
"sEmptyTable": "No hay datos para cargar en la tabla",
"sInfo": "Mostrando _START_ de _END_ de _TOTAL_ entradas",
"sInfoEmpty": "Mostrando 0 de 0 de 0 entradas",
"sInfoFiltered": "(filtradas _MAX_ entradas totales)",
"sInfoPostFix": "",
"sInfoThousands": ",",
"sLengthMenu": "Mostrar _MENU_ entradas",
"sLoadingRecords": "Cargando...",
"sProcessing": "Procesando...",
"sSearch": "Buscar:",
"sZeroRecords": "No se encontraron registros",
"oPaginate": {
"sFirst": "Primera",
"sLast": "Última",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": activar para ordenar de forma ascendente",
"sSortDescending": ": activar para ordenar de forma descendente"
}
});
vm.dtColumns = [
DTColumnBuilder.newColumn('gob_code').withTitle('Cód. Gob.'),
DTColumnBuilder.newColumn('fci_code').withTitle('Cód. FCI'),
DTColumnBuilder.newColumn('name').withTitle('NOMBRE'),
DTColumnBuilder.newColumn('status').withTitle('ESTATUS')
];
}).error(function(err){
});//Fin $http
});//Fin promise
}//Fin función
<div ng-controller="dataController as showCase">
<table datatable="" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" class="table table-striped table-bordered"></table>
</div>
POST-DATA (EDITED) If they ask: