Server Side Processing with Flask

Server Side Processing with Flask

hdoranhdoran Posts: 16Questions: 8Answers: 0

I have the code below to render a table in my browser. My tables can be huge, and so I'm trying to implement server side processing. I have added the following to the code below:

serverSide: true,
        ajax: {
            url: '/bank',
            type: 'POST'
        }

Without the code above, the function below works beautifully and everything operates as expected with pagination and other rendering, except that the table takes huge memory. However with this code, I get the entire table in the browser and lose rendering for pagination and my search boxes no longer operate.

I'm following the instructions here:

https://datatables.net/manual/server-side

Am I missing additional code I need to work with so my table render with pagination and also searches work as well?

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#mytable thead tr').clone(true).appendTo( '#mytable thead' );
    $('#mytable thead tr:eq(1) th').each( function (i) {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );

        $( 'input', this ).on( 'keyup change', function () {
            if ( table.column(i).search() !== this.value ) {
                table
                    .column(i)
                    .search( this.value )
                    .draw();
            }
        });
    });

    var table = $('#mytable').DataTable({
        orderCellsTop: true,
        fixedHeader: true,
        serverSide: true,
        ajax: {
            url: '/bank',
            type: 'POST'
        }
        dom: 'Blfrtip',
        buttons: [
            {
                extend: 'csv',
                text: 'Export as .csv'
            }
        ]
    });
});

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You will need to write the server Python code to perform the paging, searching and sorting. Or you can use a pre-built library like this:
    https://github.com/SergioLlana/datatables-flask-serverside

    I haven't used it so not sure how well it works.

    Kevin

  • hdoranhdoran Posts: 16Questions: 8Answers: 0

    Thank you, @kthorngren. Before I go any further with this work, is server side processing still the best option for dealing with extremely large tables? Or, do you or others know if other alternatives exist?

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    This FAQ explains the options for Datatables speed optimization.

    Kevin

This discussion has been closed.