1
votes

I'm having a problem with my code in Datatables server-side processing. The problem is with the pagination. My data gives me 3 pages, but only the first click on the numbers of the pagination works (doesn't matter what number I clicked). After this, any click in any number just make the table content blink. Nothing in the table changed.

Anyone can help me with some suggestions what to do? Thank you!

EDIT:

Just fixed it. Check the answer please.

My code:

$('#table').DataTable({
                    lengthChange: false,
                    pagingType: 'numbers',
                    pageLength: 20,
                    destroy: true,
                    searching: false,
                    info: false,
                    processing: false,
                    paging: true,
                    language: {
                        url: varEndPoint + 'libs/plugins/dataTables/localization/' + userLang + '.js'
                    },
                    autoWidth: false,
                    scrollCollapse: true,
                    scrollY: '400px',
                    serverSide: true,
                    ajax: {
                        url: 'Controller/Path',
                        type: 'POST',
                        dataType: 'json',
                        data: { 'entity': 'owner', 'filter': 'owner'},
                        beforeSend: function () { $('body').prepend('Loading...'); },
                        complete: function () {
                            $('.loader').remove();
                        },
                    columns: [
                        { data: 'name' },
                        { data: 'document' },
                        { data: 'account' }
                    ],
                    columnDefs: [
                        { targets: '_all', orderable: false }
                    ]
                });
1
Can you show the JSON response you get from the server for the datatable? also, I think that your server-side code is sending the same data on pagination this is why its just updating and not changing.Kulshreshth K
Can you share your Controller/Path code (method with the pagination logic) ?user4266998
I just solved. Edited my question with the resolution. Thanks.Saulo Teodoz
@Saulo Teodoz, consider adding answer to your own question. It is much better way and will help others to locate the answer easily.Gyrocode.com
@Gyrocode.com sorry about that, I'm a newbie. I will do it, thanks!Saulo Teodoz

1 Answers

1
votes

Here is the fix:

My "draw" property in response was:

int draw = Request.Form["draw"].FirstOrDefault();

Just fixed with parsing the int like this:

int draw = int.Parse(Request.Form["draw"]);

Hope it helps someone with the same problem.