Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order and filter not working #1789

Closed
aline-matos opened this issue Jul 1, 2018 · 8 comments
Closed

Order and filter not working #1789

aline-matos opened this issue Jul 1, 2018 · 8 comments
Labels

Comments

@aline-matos
Copy link

Summary of problem or feature request

Pagination works fine, but it's not ordering or filtering.

awesomescreenshot-2018-07-01t22-01-08-680z

Code snippet of problem

Route:

Route::get('home/dataTable', 'HomeController@dataTable');

Controller:

public function dataTable(Request $request)
{
    return datatables()->of(Equipments::all())->toJson();
}

Javascript:

$('.dataTable').dataTable({
        'lengthMenu': [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'Todos']],
        'processing': true,
        'serverSide': true,
        'ajax': 'home/dataTable',
        'columns': [
                { 'data': 'serial_number' },
                { 'data': 'modem_sn' },
                { 'data': 'power_supply_sn' },
                { 'data': 'name' },
                { 'data': 'equipment_type_id' },
                {
                    'data': null,
                    render: function ( data ) {
                        return (data.enabled)
                            ? '<i class="mdi mdi-circle text-success"></i> Online'
                            : '<i class="mdi mdi-circle text-danger"></i> Offline';
                    }
                }
            ],
        'language': {
            'url': 'plugins/datatables-language/Portuguese-Brasil.json'
        }
    })

JSON Response test 1:

order: [{column: "0", dir: "asc"}]

JSON Response test 2:

order: [{column: "0", dir: "desc"}]

System details

  • Ubuntu 18.04 LTS
  • PHP 7.2.7-1
  • Laravel 5.6
  • PostgreSQL 9.5.13
@yajra
Copy link
Owner

yajra commented Jul 6, 2018

That's odd. Can you try inspecting the ajax request with APP_DEBUG=true and review the input values submitted? It seems like the javascript is fixed on ordering with column 0.

@yajra yajra added the question label Jul 6, 2018
@aline-matos
Copy link
Author

aline-matos commented Jul 10, 2018

@yajra I'm using APP_DEBUG=true

Post 1:

draw: 1
columns[0][data]: serial_number
columns[0][name]: serial_number
columns[0][searchable]: true
columns[0][orderable]: true
columns[0][search][value]: 
columns[0][search][regex]: false
columns[1][data]: modem_sn
columns[1][name]: 
columns[1][searchable]: true
columns[1][orderable]: true
columns[1][search][value]: 
columns[1][search][regex]: false
columns[2][data]: power_supply_sn
columns[2][name]: 
columns[2][searchable]: true
columns[2][orderable]: true
columns[2][search][value]: 
columns[2][search][regex]: false
columns[3][data]: name
columns[3][name]: 
columns[3][searchable]: true
columns[3][orderable]: true
columns[3][search][value]: 
columns[3][search][regex]: false
columns[4][data]: equipment_type_id
columns[4][name]: 
columns[4][searchable]: true
columns[4][orderable]: true
columns[4][search][value]: 
columns[4][search][regex]: false
columns[5][data]: 
columns[5][name]: 
columns[5][searchable]: true
columns[5][orderable]: true
columns[5][search][value]: 
columns[5][search][regex]: false
order[0][column]: 0
order[0][dir]: asc
start: 0
length: 10
search[value]: 
search[regex]: false

Response 1:
https://jsoneditoronline.org/?id=4c77e2bbf7d241b880143e17935b6134

Post 2:

draw: 2
columns[0][data]: serial_number
columns[0][name]: serial_number
columns[0][searchable]: true
columns[0][orderable]: true
columns[0][search][value]: 
columns[0][search][regex]: false
columns[1][data]: modem_sn
columns[1][name]: 
columns[1][searchable]: true
columns[1][orderable]: true
columns[1][search][value]: 
columns[1][search][regex]: false
columns[2][data]: power_supply_sn
columns[2][name]: 
columns[2][searchable]: true
columns[2][orderable]: true
columns[2][search][value]: 
columns[2][search][regex]: false
columns[3][data]: name
columns[3][name]: 
columns[3][searchable]: true
columns[3][orderable]: true
columns[3][search][value]: 
columns[3][search][regex]: false
columns[4][data]: equipment_type_id
columns[4][name]: 
columns[4][searchable]: true
columns[4][orderable]: true
columns[4][search][value]: 
columns[4][search][regex]: false
columns[5][data]: 
columns[5][name]: 
columns[5][searchable]: true
columns[5][orderable]: true
columns[5][search][value]: 
columns[5][search][regex]: false
order[0][column]: 0
order[0][dir]: desc
start: 0
length: 10
search[value]: 
search[regex]: false

Response 2:
https://jsoneditoronline.org/?id=28ae03ff8d694d5a93977799eac1fa43

@aline-matos
Copy link
Author

aline-matos commented Jul 23, 2018

@yajra Does this problem have anything to do with me using Postgres?

@oranges13
Copy link

I have this exact same problem, and I'm using MSSql (sqlsrv). The service implementation works but sorting / searching does not work.

@aline-matos
Copy link
Author

Any updates of this issue?

@aline-matos
Copy link
Author

I have this exact same problem, and I'm using MSSql (sqlsrv). The service implementation works but sorting / searching does not work.

@oranges13 did you solve your issue?

@oranges13
Copy link

@aline-matos I don't recall exactly what the resolution was, but I do know that the service implementation out-of-the-box did not work for this exact reason. I will try to find the resource I used to modify my application that finally got it working.

@aline-matos
Copy link
Author

I solve this inssue by overriding the Request class with @sgotre suggestion:
https://github.com/teraone/laravel-datatables/commit/9db3bc72af378dd8327fa8ad60c2c83a96c9c1ab

yajra pushed a commit that referenced this issue Mar 26, 2019
When dt Request is sent as application/json instead of multipart/form-data
and when in ColumnDef boolean values are used the search does not work. 
 
(Angular 6 HTTPClient for example)

might affect #1789
ExpDevStar added a commit to ExpDevStar/Datatables-in-Laravel that referenced this issue Dec 26, 2019
When dt Request is sent as application/json instead of multipart/form-data
and when in ColumnDef boolean values are used the search does not work. 
 
(Angular 6 HTTPClient for example)

might affect yajra/laravel-datatables#1789
ExpDevStar added a commit to ExpDevStar/Datatables-in-Laravel that referenced this issue Dec 26, 2019
When dt Request is sent as application/json instead of multipart/form-data
and when in ColumnDef boolean values are used the search does not work. 
 
(Angular 6 HTTPClient for example)

might affect yajra/laravel-datatables#1789
goldbright00000 added a commit to goldbright00000/laravel-project that referenced this issue Mar 22, 2020
When dt Request is sent as application/json instead of multipart/form-data
and when in ColumnDef boolean values are used the search does not work. 
 
(Angular 6 HTTPClient for example)

might affect yajra/laravel-datatables#1789
goldbright00000 added a commit to goldbright00000/laravel-project that referenced this issue Mar 22, 2020
When dt Request is sent as application/json instead of multipart/form-data
and when in ColumnDef boolean values are used the search does not work. 
 
(Angular 6 HTTPClient for example)

might affect yajra/laravel-datatables#1789
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants