YADCF multi_select filter with server side

Deadly 提交于 2019-12-12 03:23:22

问题


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...


回答1:


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)



来源:https://stackoverflow.com/questions/27824704/yadcf-multi-select-filter-with-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!