Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm a bit confused on the usage of angular data tables, particularly the server side processing section. I've got a list of columns on the DOM, picture it like this.

Col A
Col B
Col C
Col D
Col E
etc...

I want to be able to dynamically fetch the data for each column from the backend, based on which column I click on. So if I selected Col A and Col B, I would want some request to be fired off,

function ServerSideProcessingCtrl($scope, DTOptionsBuilder, DTColumnBuilder) {

    $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('ajax', {
             url: '/my_route',
             type: 'POST',

             // this is the part that I would like to do but cannot figure out
             data: {
                 chosen_columns: ["col A", "col B"]
             }
        })
        .withOption('serverSide', true);

    $scope.dtColumns = [
        DTColumnBuilder.newColumn('col_a').withTitle('Col A'),
        DTColumnBuilder.newColumn('col_b').withTitle('Col B'),

        // would like to be able to add more dynamically as a response
        // to user clicks on the frontend....
    ];
}

So I am able to grab data from the backend, but I am not sure how to change the request I am firing off once the DTOptionsBuilder/DTColumnBuilder has been initialized. Are there any strategies for doing this? This API is a bit confusing to me, I looked at the regular Jquery datatables that this thing was based off, and it was similarly confusing.

Is there a way to do what I am asking, or do all the columns I plan to use need to be present in the initialization?

I do know all the possible columns I will need at initialization, so I suppose I could set the visibility of the columns I have not selected to be false, but that seems like a suboptimal solution.

I also haven't found a way to get access to the columns inside $scope.dtColumns on the backend, short of passing them in as a comma separted string in the "data" part of the request, like this.

data: {
    columns: "Col A, Col B"
}

Which of course defeats my whole "dynamically selecting columns to use in the request" use case.

Can someone please give me some advice as to how to use this library in the way that I am wanting to, if it is possible?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.