NunoRibeiro
NunoRibeiro

Reputation: 511

YADCF multi_select filter with server side

Working with AngularJS, I have a DataTable() working in serverSide mode, using the YADCF filters. Is it possible to use the multi_select filter (whith chosen or select2) while working on ServerSide? Can I manually introduce the parameters of search? In this case I want to use that filter on the column #6 ("estado") that means "The state" of a proccess.

The code from the myApp.controller

var table = $('#tbl').DataTable({
        stateSave: true,
        stateDuration: -1,
        //sRowSelect: "multi",
        language: sharedProperties.getLanguageDatatable(),
        dom: '<"toolbar">T<"clear">lfrtip',            
        "columnDefs": [
            { "data": "processosId", "targets": 0, "visible": false, "searchable": false },
            { "data": "utilizadoresId", "targets": 1, "visible": false, "searchable": false },
            { "data": "entidadesId", "targets": 2, "visible": false, "searchable": false },
            { "data": "numero", "targets": 3 },
            { "data": "nomeEntidade", "targets": 4, "visible":entidadeCol },
            { "data": "nomeUtilizador", "targets": 5, "visible":utilizadorCol },
            { "data": "estado", "targets": 6 },                
        ],
        serverSide: true,
        ajax: {
            "url": urlProcessos,
            "error": function (reason) {
                if (reason.status == 401) { // Not Authorized
                    self.location = '#/logout';
                }
            }
        },
});

    yadcf.init(table,
    [
        { column_number: 3, filter_type: 'text', filter_default_label: "" },
        { column_number: 4, filter_type: 'text', filter_default_label: "" },
        { column_number: 5, filter_type: 'text', filter_default_label: "" },
        { column_number: 6, filter_type: 'multi_select', filter_default_label: "", select_type:'chosen' },            
    ]);

    $scope.newProcess = function () {            
        table.columns(6).search('Novo').draw();

    }

    $scope.openProcess = function () {
        table.columns(6).search('Aberto').draw();
    }

When I filter the first time, because its server-side it only have access to the proccess with that state, so it's impossible to chose one or more states...

Upvotes: 0

Views: 1316

Answers (1)

Daniel
Daniel

Reputation: 37061

In case that you want to trigger yadcf filter you better use yadcf api

I suggest you to replace

table.columns(6).search('Novo').draw();

and

table.columns(6).search('Aberto').draw();

with something like this

yadcf.exFilterColumn(oTable, [[0, ['Novo']]], true);

and

yadcf.exFilterColumn(oTable, [[0, ['Aberto']]], true);

In case that you want to filter multiple values, you can add more to the array, like this

yadcf.exFilterColumn(oTable, [[0, ['Novo', 'Aberto']]], true);

read more about exFilterColumn api

note that the third true argument should be used when filtering am ajax sourced datatable that was already loaded (no docs for that yet)

Upvotes: 0

Related Questions