I am displaying a 20k row datatable through django. It is very slow to render. database is sql.

I am displaying a 20k row datatable through django. It is very slow to render. database is sql.

NishthaNishtha Posts: 6Questions: 2Answers: 0
<div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="call">
        <div class="spacer"></div>
        <table id="example" class="table table-bordered" style="width:100%">
            <thead>
                <tr>
                    <th> Variable Name</th>
                    <th>Return Type</th>
                    <th>Rule A</th>

                </tr>
            </thead>
            <tbody>

            {%  for data  in variable %}
                <tr>
                    <td>{{  data.variable_name }}</td>
                    <td>{{  data.return_type }}</td>
                    <td>{{  data.rule_a }}</td>

                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>

This question has an accepted answers - jump to answer

Answers

  • YOMYOM Posts: 53Questions: 22Answers: 1
    edited July 2020

    With 20k records I would recommend paging and/or serverside processing to improve performance.

  • NishthaNishtha Posts: 6Questions: 2Answers: 0

    @YOM I am using Django models to get data from sql database, I am not sure how to convert it into Ajax data?

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited July 2020 Answer ✓

    I am using Django models to get data from sql database, I am not sure how to convert it into Ajax data?

    Maybe this tutorial will help. The response should be JSON formatted:
    https://simpleisbetterthancomplex.com/tutorial/2016/07/27/how-to-return-json-encoded-response.html

    Datatables doesn't have Django server side code but you can find some third party Django apps for Datatables, like this:
    https://pypi.org/project/django-datatables-view/

    Looks like it supports server side process (paging) to return one page of data at a time. This will increase the render speed.

    Kevin

  • YOMYOM Posts: 53Questions: 22Answers: 1

    If you did want to use one of the datatables serverside libraries, you could alternatively create an AWS Lambda function or host an apache server to handle server side processing outside of your Django app. It all depends on your implementation whether that's worth the effort.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    This section of the FAQ should help, it discusses various techniques to improve performance,

    Cheers,

    Colin

This discussion has been closed.