Ajax call only first time and after will disabled till page reload

Ajax call only first time and after will disabled till page reload

MausinoMausino Posts: 61Questions: 19Answers: 0
edited May 2021 in DataTables 1.10

Hi, i want ask where or is some examples where i can by serverside by DataTable only load ajax on submit button and filtering and sorting will do only localy in browser with data which requested from server ????

My only one idea is do the request by server and on page pass the data to Datatables that will behavior as only client side Datatable.. and in Editor i will call by ajax separately....

I saw example with editor where you can edit data and will send by ajax only on save button... that i am thinking if is same way possible to get init reqest by Datatable and after all other things like filtering, sorting, ordering will do with only loaded data by this init request...

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin

    Do you mean something like this? The first page of data is in the HTML loaded from the server, but subsequent data requests are made to the server via Ajax.

    Allan

  • MausinoMausino Posts: 61Questions: 19Answers: 0

    @Alan thank you for the response.. i read the docs and look on example.. it looks straightforward but one question

    How we pass this value to deferLoading from ajax call from serverside ??? because if i am looking on https://datatables.net/manual/server-side chapter Returned data i dont see any value which can fill the number of deferLoading...

    And if must be the number in DeferLoading defined before ajax call.. i don't see the sense of it.... (because i dont know the value before ajax call)

    I have in test datatables 100K rows... on form submit i pass this values to parameters of datatable.. this makes ajax call and rentur me for example 1K filtered row...

    Now if i want filter this 1K row now only on client-side (in browser) how i will set this value to deferLoading ?

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

    I think Allan misread the issue - deferLoading is used when the data is already in the DOM/HTML, so that first ajax call doesn't need to be made, so that won't help you here.

    That said, with serverSide, it will always return the number of values determined by the current page length. That's not changable.

    Likewise, if you've enabled serverSide, everything (sorting/paging/filtering) will be performed on the server - you can't load the data then have the client do those operations. It sounds like you're requirements won't be achievable without changing the flow or modifying the code.

    Colin

  • MausinoMausino Posts: 61Questions: 19Answers: 0

    @colin Hi, thank you for explanation.

    In my case i showing the markers on the maps which are generated from dataTables.
    For those action i need have location, distance and unit type (like km, mil etc). This are send as parameters via dataTables ajax call to server.. there i need get by google geocode the gps and by this i search by distance the markers and calculate by harversine formula the distance of marker to central marker(searched location)...

    From 100K dataset i get for example 1K (which is not so big to handle on browser side).

    That's why i had a idea if can load by ajax initial dataset of data and after works with them localy (client side) like sort, search, paging). And i wanted perform load new dataset of data only on button submit.

    I cant find the example (i am trying secod day found this what i saw) of Editor where you can edit multiple records by Editor but they will process only by cancel(throw changes) or save button(send changes) to server..

    And my idea was why we can also in Datatables can load new dataset of data only by request for example Refresh button.

    I waste so much resources by searching and parsing by server and it can be handle by browser... that is my idea maybe for future where new dataset of data for serverside processing will conditionaly by button or some action :smile:

    now i have only 2 options.. browser or server... i hope that should be middle way

    sorry for english

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    If I understand correctly you want to click a button and fetch a new set of data from the server. You can use ajax.data as a function. See examples in the docs and this example of send dynamic custom parameters to the server. This works whether you use server side processing or not. You can use ajax.reload() in your button click event to fetch a new set of data.

    HTH,
    Kevin

  • MausinoMausino Posts: 61Questions: 19Answers: 0
    edited June 2021

    @kthorngren @allan @colin

    Please look on bottom where i described new feature/ my idea which can help many developers

    Both ajax.data and ajax.reload() i am using now in my dataTables.

    I solved my case now that i have client side dataTable and i parsing the data without ajax call to dataTables and separate search from dataTables. Now DT is only observers on page where you can sort, filter, search only with dataset which i parsed on init loading of page to dataTable.

    The dark side is that i must reload page on search if i want add new data for now... (i will try <table></table> load by ajax in html and this heck will maybe solve my issue with reloading if i want parse new data.

    I don't waste your time guys.. i really appreciate the great Datatables .. but if my system will use around 100 users in real time.. for me is insane to every action sort, every letter in filtering, or paging send new request and new draw back if still we are working with same results as on fist draw.. i see it on your examples with server side.. i can by 10sec working with data make around 20 draws (that means requests to servers with new datasets on every draw)

    This look insane for me.. if will do this 100 users... and can't image if 1K or more :)

    This is my idea for your feature: (if you throw it.. don't matter, but i think will good for many others programmers)

    Possibility with options "processing": true, "serverSide": true,
    also have other one for example deferByActionLoading and this will have own options like

    maxResults: All or Integer
    // user can define how many results want load from serverSide to datatable to which will work as clientside
    lengthMenu: [ 10, 25, 50, 75, 100 ]
    // how want that DT will paginate this results on init dataset
    initAction: Button, function, etc for new ajax.reload of DT
    // on which action will load next dataset of data as new draw

    How it should works:

    If DT will have option deferByActionLoading it will load on fist time by maxResults the data into DataTables.... after will DT works as client side DT... data will paginated by lengMenu in deferByActionLoading option object. New data will load by ajax to server only if initAction will condition will fulfilled (like button or function or whatever)

    The main reason is if i have server side loading i don't need on first draw of data in Datatable if my results are under 1K or less on every action like filter, sort or search send new and new request to server, if browser should work with this same results, because

    If i will order 1K rows of results still will same 1K rows of results, if search from 1K results will same if i send request to servers and will have 10 results from 100K or 10 from 1K which was processed by browser...

    My only flustration is if i want do some easy things in DT and by serverside by 10 sec i make 20 draws from database of 100K rows which still working with same 1K results as on fist draw

    Sorry i don't want disturb you more with this ticket.. I let on your if my idea have for you and other user use in real world. sorry for english again

Sign In or Register to comment.