I have 10,000 of row data and for 30 mins to 40 mins I want to store it in localstorage.

I have 10,000 of row data and for 30 mins to 40 mins I want to store it in localstorage.

GeorgDGeorgD Posts: 2Questions: 1Answers: 0

I am using python flask for backend and html, css, js for frontend.

I am using datatables in 3 different html pages within same domain, where in each page data are around 5,000 to 10,000. So I want to temperorly store it in local storage say around 30 to 40min. So that if user revisits that page within that time it should load data from local storage. If the time exceeds then it should fetch from server.

I tried few ways but it's not working. If anyone could provide the solution or point out to some references, it would highly helpful.

Thank you.

Answers

  • kthorngrenkthorngren Posts: 20,342Questions: 26Answers: 4,775
    edited February 22

    Using local storage tor the table data is not something built into Datatables. However, Datatables doesn't dictate the source of the data. You can manage the local storage and fetch the data from it for Datatables to use. You can use data to populate the Datatable at initialization or use rows.add() to add the rows after initialization. See the Data Sources docs for more info.

    Make sure the data conforms to the supported data source types.

    Kevin

  • kthorngrenkthorngren Posts: 20,342Questions: 26Answers: 4,775

    In addition if the table is not stored locally then you can use jQuery ajax() to fetch the data and, in the success function, use data to apply the table data during initialization.

    Kevin

  • GeorgDGeorgD Posts: 2Questions: 1Answers: 0
    edited February 27

    Thank you for suggession, I have gone through the documentation of "data" and "row.add()". My scenario is slightly different, I will be reading data from database in backend python flask file and routing traffic directly to .html page, something like "return render_template('test.html', data=data_query)".

    And in frontend html page I will be using like,

    <table id="example" class="display nowrap" style="width:100%">
        <thead>
            <tr>
                <th>Column 0</th>
                <th>Column 1</th>
                <th>Column 2</th>
                .
                .
            </tr>
        </thead>
        <tbody>
            {% for row in data %}
            <td>{{ row[0] }}</td>
            <td>{{ row[1] }}</td>
            <td>{{ row[2] }}</td>
            .
            .
        </tbody>
    </table>
    

    So how to save this data in localStorage or browser database for around 30minutes?

    I am new to front end, if there is an example please let me know

    Thank you.

  • kthorngrenkthorngren Posts: 20,342Questions: 26Answers: 4,775

    Stack Overflow is a more suitable forum for general Javascript and Web development questions. This forum is for Datatables related questions.

    Kevin

Sign In or Register to comment.