serverSide and pagination issues

serverSide and pagination issues

phaorisphaoris Posts: 9Questions: 1Answers: 0
edited June 2014 in Free community support

hi guys, hi Allan,

first, thank you for this plugin

i have an issue with datatables rendering the data,

i'm using laravel and bllim's package to get the data from my DB, i have them linked to a route like localhost/myapp/public/api/datatable/1

where the last number in the url change to display the data by country...

i have a table with 5 tabs, so far, i do get all the data display in each tab but the problem is it's not filtering when i search for something, and the filter is "columns" is not working, nor the pagination

so, i investigated and found that when i search for something in my table, the query is always the same select foo from bar where bar.country_id = 1 for say, no matter what i type it's always the same query performing, there is no select foo from bar where bar.country_id = 1 and mycolumn like "%Canada%" for example

i tried to setup a jsbin like this http://live.datatables.net/idinat/78/edit
but it's working fine,

also, the yadcf plugin is not working , dunno why either

so here is a sample code with my data and how i call it:

        jQuery(document).ready(function() {

            $('.nav-justified ul li').first().addClass('active');
            $('#tab_191').addClass('active');

            var centres = [191,194,197,198,199];

            $.each(centres, function(index, val) {
                index++;
                var table = $('#centre_' + val).dataTable({
                    "language": { "url": "assets/localisation/fr_FR.json"},
                    "dom": 'C<"clear">lfrtip',
                    "stateSave": true,
                    "autoWidth": true,
                    "searching": true,
                    "sort": true,
                    "info": true,
                    "paging": "full",
                    "lengthMenu": [[10,25,50, -1], [10,25,50,'Tout']],
                    "autoWidth": true,
                    "processing": true,
                    "serverSide": true,
                    "ajax": {
                        'url' : "{{URL::to('api/datatable')}}/" + index,
                        'type': 'GET',
                        'contentType': 'application/json; charset=utf8',
                        'data': function(data){
                           return data = JSON.stringify(data);
                        }
                    },
                    "columns":[
                        { "width": "200px", "orderSequence": [ "desc" ] },
                        { "width": "200px" },
                        { "searchable": false, "width": "135px" }
                    ],

            });
        });

        function formatDateTime(dateTime, formatting){
            if (dateTime == null || dateTime == '') {
                return '';
            }else{
                return moment(dateTime).format(formatting);
            }
        }

the json returned from localhost/myapp/public/api/datatable/1 is something like this:

{
    "draw": 0,
    "recordsTotal": 4,
    "recordsFiltered": 4,
    "data": [
        [
            3,
            "Toto",
            "<td>
                <p>
                    <a href='#' class='btn yellow'><i class='fa fa-search'></i>
                    </a><a href='#' class='btn blue'><i class='fa fa-file-o'></i></a>
                    <a href='#' class='btn purple'><i class='fa fa-times'></i></a>
                </p>
            </td>"
        ],
        [
            5,
            "Titi",
            "<td>
                <p>
                    <a href='#' class='btn yellow'><i class='fa fa-search'></i></a>
                    <a href='#' class='btn blue'><i class='fa fa-file-o'></i>
                    </a><a href='#' class='btn purple'><i class='fa fa-times'></i></a>
                </p>
            </td>"
        ],
        [
            6,
            "venti",
            "<td>
                <p>
                    <a href='#' class='btn yellow'><i class='fa fa-search'></i></a>
                    <a href='#' class='btn blue'><i class='fa fa-file-o'></i></a>
                    <a href='#' class='btn purple'><i class='fa fa-times'></i></a>
                </p>
            </td>"
        ],
        [
            8,
            "pablo",
            "<td>
                <p>
                    <a href='#' class='btn yellow'><i class='fa fa-search'></i></a>
                    <a href='#' class='btn blue'><i class='fa fa-file-o'></i></a>
                    <a href='#' class='btn purple'><i class='fa fa-times'></i></a>
                </p>
            </td>"
        ]
    ]
}

i dunno if someone could help but really, REALLY i'm in trouble, i have to submit this project next week and i'm not even half done with it coz of this problem, i wasted a week trying to solve this without luck, so this post is my last chance getting this done.

*edit: here is the datatable debug if it helps http://debug.datatables.net/udoban

Replies

  • phaorisphaoris Posts: 9Questions: 1Answers: 0

    any help plz ?

  • phaorisphaoris Posts: 9Questions: 1Answers: 0

    plz guys ?

  • phaorisphaoris Posts: 9Questions: 1Answers: 0

    up ?

  • DaharkDahark Posts: 28Questions: 1Answers: 0

    Hey Phaoris,

    I believe your problem is that you have set serverSide : true
    When serverSide Processing is set to true, then all the Filtering and searching is done on a server and the build in filter and search functions are disabled.

    can you try with serverSide : false?

    Best regards

  • phaorisphaoris Posts: 9Questions: 1Answers: 0

    Dahak, you saved my entire week :)
    thanks alot Dahark

    i'm still investigating regarding the yadcf plugin to filter my columns :)

    kind regards

  • DaharkDahark Posts: 28Questions: 1Answers: 0

    Hello Phaoris,

    I'm glad to hear that it worked for you...

    have a nice weekend :-)

This discussion has been closed.