1

Already tried:

Similar question to the one solved in a previous question about promise functions. Having searched through all of this I still can't quite understand what to do with my following problem:

Problem:

I am trying to load in user specified data to an angular-datatable table. The user can select which fields they want to view. The best way I could find to do this was by loading the column data via promise.

However I also want to add an actions column to delete and edit rows of data so I am trying to push this column data onto the settings array. This of course does not work because it is a promise object not the actual array.

I have no idea how to arrange the functions in such a way to add the last column this way (I'm a reasonably new developer in training). Here is the extract of code from the controller:

function angularDataTable(DTOptionsBuilder, DTColumnBuilder, $q, $resource) {
    var vm = this;
    vm.dtOptions = DTOptionsBuilder.fromSource('resources/customerData.json')
            .withPaginationType('full_numbers');
    vm.dtColumns = $resource('resources/fieldSelection.json').query().$promise;
    //So I know this is the incorrect way to work with promise objects but I don't know how to rearrange it to work.
    vm.dtColumns.push(DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml));
    vm.edit = edit;
    vm.delRow = deleteRow;
    
    function actionsHtml(data, type, full, meta) {
        return '<button class="btn btn-warning" ng-click="table.edit(' + data.id + ')">' +
            '   <i class="fa fa-edit"></i>' +
            '</button>&nbsp;' +
            '<button class="btn btn-danger" ng-click="table.delRow(' + data.id + ')">' +
            '   <i class="fa fa-trash-o"></i>' +
            '</button>';
    }
    
    function edit(id) {
        console.log('edit');
    }
    function deleteRow(id) {
        console.log(id);
    }
}

Full code on github

1 Answer 1

1

Look into the tabletools section http://l-lin.github.io/angular-datatables/#/withTableTools

Additionally, if you define your columns in your controller you can hide and show columns using notVisibile() and visible(). See http://l-lin.github.io/angular-datatables/#/rerender for an example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.