laravel-datatables: SearchPanes not working

Summary of problem or feature request

Using the code described here (https://github.com/yajra/laravel-datatables/pull/2475) I receive this javascript errors (many of this):

DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter 'shown' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

Code snippet of problem

I`m using server-side processing with laravel, returning this code

{
    "draw": 1,
    "recordsTotal": 1614,
    "recordsFiltered": 1614,
    "data": [
        .....
        {
            "id": 1651,
            "name": "ALTHOFF 14",
            "regional_id": 36,
            "company_brand_id": 38,
            "bandeira": "ALTHOFF",
            "regional": "SANTA CATARINA",
            "DT_RowId": 1651
        },
        {
            "id": 1652,
            "name": "ANDREAZZA ARROIO DO SAL",
            "regional_id": 35,
            "company_brand_id": 39,
            "bandeira": "ANDREAZZA",
            "regional": "RIO GRANDE DO SUL",
            "DT_RowId": 1652
        },
        {
            "id": 1653,
            "name": "ANDREAZZA BELA VISTA",
            "regional_id": 35,
            "company_brand_id": 39,
            "bandeira": "ANDREAZZA",
            "regional": "RIO GRANDE DO SUL",
            "DT_RowId": 1653
        },
        ........
    ],
    "queries": [
        {
            "query": "select count(*) as aggregate from (select '1' as \"row_count\" from \"sales_points\" where \"sales_points\".\"deleted_at\" is null) count_row_table",
            "bindings": [],
            "time": "9.4"
        },
        {
            "query": "select * from \"sales_points\" where \"sales_points\".\"deleted_at\" is null order by \"name\" asc limit 10 offset 0",
            "bindings": [],
            "time": "12.27"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.98"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.47"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "35"
            ],
            "time": "1.73"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "37"
            ],
            "time": "1.48"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "37"
            ],
            "time": "1.68"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "35"
            ],
            "time": "1.57"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.68"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.57"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.7"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.82"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.8"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.5"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.67"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.44"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.66"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.44"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.44"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.55"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.77"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.8"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.84"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.85"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "38"
            ],
            "time": "1.77"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "36"
            ],
            "time": "1.71"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "39"
            ],
            "time": "1.77"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "39"
            ],
            "time": "1.73"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "35"
            ],
            "time": "1.71"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "39"
            ],
            "time": "1.57"
        },
        {
            "query": "select * from \"company_brands\" where \"company_brands\".\"id\" = ? limit 1",
            "bindings": [
                "39"
            ],
            "time": "1.76"
        },
        {
            "query": "select * from \"regionals\" where \"regionals\".\"id\" = ? limit 1",
            "bindings": [
                "35"
            ],
            "time": "1.81"
        }
    ],
    "input": {
        "draw": "1",
        "columns": [
            {
                "data": "name",
                "name": "name",
                "searchable": "true",
                "orderable": "true",
                "search": {
                    "value": null,
                    "regex": "false"
                }
            },
            {
                "data": "bandeira",
                "name": "company_brand_id",
                "searchable": "true",
                "orderable": "true",
                "search": {
                    "value": null,
                    "regex": "false"
                }
            },
            {
                "data": "cnpj",
                "name": "cnpj",
                "searchable": "true",
                "orderable": "true",
                "search": {
                    "value": null,
                    "regex": "false"
                }
            },
            {
                "data": "regional",
                "name": "regional",
                "searchable": "true",
                "orderable": "true",
                "search": {
                    "value": null,
                    "regex": "false"
                }
            },
            {
                "data": "4",
                "name": null,
                "searchable": "true",
                "orderable": "false",
                "search": {
                    "value": null,
                    "regex": "false"
                }
            }
        ],
        "order": [
            {
                "column": "0",
                "dir": "asc"
            }
        ],
        "start": "0",
        "length": "10",
        "search": {
            "value": null,
            "regex": "false"
        },
        "deleted_register": "false",
        "_": "1616702996147"
    },
    "searchPanes": {
        "options": {
            "regional": [
                {
                    "value": 35,
                    "label": "RIO GRANDE DO SUL"
                },
                {
                    "value": 36,
                    "label": "SANTA CATARINA"
                },
                {
                    "value": 37,
                    "label": "PARANÁ"
                }
            ]
        }
    }
}

My suspect is laravel doesn`t returns the code that search pane expects, as is:

....
"searchPanes": {
        "options": {
            "regional": [
                {
                    "value": 30,
                    "label": "RS"
                    "total" => ?????,
                    "count" => ????,
                },
...

System details

  • Operating System Ubuntu 20.04.2 LTS
  • PHP Version 7.4.3
  • Laravel Version 6.20.20
  • Laravel-Datatables Version 9.17.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@mattpramschufer there is a 3rd callback param that you can use to customize the filters.

$users = User::query()->select('id as value', 'name as label')->get();
...
->searchPane('user_id', $users, function($query, $values) {
    $query->whereIn('user_id', $values);
})

Okay, I just created a quick demo app from scratch to hopefully fix this issue. Please see https://github.com/yajra/dt-searchpanes-demo.

Hope this helps.

– Edit –

I have used your Pair helper and that still didn’t resolve the issue of unknown parameter ‘shown’ for row 0 i had to add the total and count keys to your function

Good catch, I have disabled the error modal on my config for that annoying message 😃

$.fn.dataTable.ext.errMode = 'none';