# Load DataTables options/ columns/ columnDefs with promise

Sometimes, your DataTable options/columns/columnDefs are stored or computed server side. All you need to do is to return the expected result as a promise.

angular.module('showcase.loadOptionsWithPromise', ['datatables', 'ngResource']) .controller('LoadOptionsWithPromiseCtrl', LoadOptionsWithPromiseCtrl); function LoadOptionsWithPromiseCtrl($q, $resource) { var vm = this; vm.dtOptions = $resource('dtOptions.json').get().$promise; vm.dtColumns = $resource('dtColumns.json').query().$promise; }

dtOptions.json

{ "ajax": "/angular-datatables/data.json", "dom": "pitrfl", "pagingType": "full_numbers" }

dtColumns.json

[{ "data": "id", "title": "ID" }, { "data": "firstName", "title": "First name" }, { "data": "lastName", "title": "Last name", "visible": false }]