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.
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
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 userows.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
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
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,
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.
Stack Overflow is a more suitable forum for general Javascript and Web development questions. This forum is for Datatables related questions.
Kevin