How to do this?

How to do this?

morlacmorlac Posts: 5Questions: 0Answers: 0
edited July 2009 in General
Hello

Is there a way to disable Ajax data load when the user clicks the column sort buttons or search for data?
I cannot control the server side script which retrieves the data.
In effect, sorting and search well be limited in function on the current dataset instead of sending the request to server.
Am using DT 1.5b11.

Thanks
Hadi

Replies

  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Hadi,

    When you a using sAjaxSource, if you specify bServerSide: true, then all requests will be made to the server. If however, you leave bServerSide as false (which is the default value), then DataTables will get the information from the Ajax load only once - which I believe is what you are looking for.

    Two examples:
    http://datatables.net/1.5-beta/examples/data_sources/ajax.html
    http://datatables.net/1.5-beta/examples/data_sources/server_side.html

    Regards,
    Allan
  • morlacmorlac Posts: 5Questions: 0Answers: 0
    Hi Allan

    True, but still I would need to keep the pagination Ajax activated and currently implementing the Data Pipeline using your supplied example.
    You see, sometimes, I get more than 2,000 records and that killed almost every browser I tried it on.
    Because of the huge amount of data is the reason why I need to restrict the search and sort on the available data only.
    With the data pipeline, I will be able to retrieve 200 to 300 records at a time and that works perfectly.
    Perhaps, an event like OnSort, OnSearch where I can set bServerSide to false and then back when I need more data like using the pagination buttons events would be a good feature.

    What do you think?

    Best Regards,
    Hadi
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Hadi,

    The problem with this is that you would then be limiting your filtering and sorting to a sub-set of the original data - is this really what you want to do? For example, if I order by the first column and then go to page 20 and do a filter - then it will only be using the data for page 20 (plus a little more if you are using pipelining).

    Why do you need to get 2'000 rows if you are using server-side processing? Surely the whole point is that you only get rows in small groups and let the server do all the hard work?

    Regards,
    Allan
  • morlacmorlac Posts: 5Questions: 0Answers: 0
    Hi Allan

    What you are saying is correct. The server should carry the work but due to the nature of the server, I cannot modify the the script in a way to allow filtering. Maybe sorting but that would be limited to one column and I cannot sort other columns. Otherwise I would have implemented it and got it working fine.

    So far, the users sometimes request huge amounts of data. I implemented the data pipeline earlier today which is fine and is exactly what I need. I understand that the search and sorting will be limited to the available dataset currently loaded and thats fine for the moment.
    In the future I will try to convince the system to search or sort on the server level but so far I cannot do that.

    So, the question is, if its possible, I would like to use as a temporary measure tell I get around to fixing the server side code.
    If it isnt doable without modifying the datatables script, then I have to live with the limitations for the time being.
    I thought about it for a while, and I the best I could think of is an OnPreSort/OnPostSort kind of event to set the bServerSide to false then to true.

    What do you think?
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Hadi,

    Sounds like an interesting problem - you want to do server-side processing, when you don't actually have full access to the server! Purely out of interest, what kind of setup allows you to read the database (I assume it is a database), but not filter on it, and allows sorting on only one column?

    I have thought about adding 'event' handler functions for sorting etc, but I want to do this in a very generic way, while ensuring that there is no performance hit - looking to 1.6 for that... Having said that, I'm not sure that simply setting bServerSide to false/true would do what is required for you. DataTables wasn't designed with the idea that features could be changed on-the-fly. You can get away with doing that for some, but not all, and this one might be quite involved... Therefore, I think your only option here would be to modify the DataTables script...

    Sorry I can't be of more help with this one just now.

    Regards,
    Allan
  • morlacmorlac Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Thats what I figured from reading the source regarding the realtime option change. I guess Ill have to engineer something.
    The system is using Ez Publish from ez.no and am using a custom module that is encrypted. Ez is a kind of CMS similar but more complicated than Drupal.
    In general, when retrieving data using the ez-fetch function, some pre-programmed sorting and filtering is available. ex. publish date.
    In my case, this would be the column I can sort only easily.
    Other columns in my case are displaying data embedded deep inside the object, and they are custom attribute.
    In order to filter on them, I have to write custom attribute filters and that is a pain in the b***.
    My experience is somewhat limited due to the steep learning curve for ez so I might be missing a simple functionality here or there.

    In any case, am looking forward to 1.6 and stable 1.5.
    One of the things I had to change so far is the JSON request. Ez for example uses clean URL in a specific way that is not compatible with datatables.
    Perhaps a template base URL generator could be more generic than the current implementation. Just an idea.

    Thanks Allan for such great work and keep up the good work.

    Best Regards,
    Hadi
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    HI Hadi,

    Interesting one. Does Ez Publish allow for reading information from it's database such that you could put your own script somewhere in the middle? Just do your own reads rather than mucking around with their stuff - should be safe if it's read only ;-)

    Regarding 1.6 - hehe - that's some way off, but I've got plans... 1.5 however should be just around the corner...

    I'm not sure sure what you mean by a base URL generator? You can modify the URL and the information that DataTables attempts to get it's information from through the custom get functions: http://datatables.net/1.5-beta/examples/server_side/custom_vars.html

    Regards,
    Allan
  • morlacmorlac Posts: 5Questions: 0Answers: 0
    Hi Allan,
    I assume you mean intercepting the request in midway which is not possible.
    The system is very customizable, hard but doable.
    When you create a custom class/Custom content type, you add some attributes to it, like Title, Date...etc
    In my case, those attribute are custom built and as such, the default available fetching subsystem cannot reference them. For that I have to build a custom attribute filter, which will allow me to use sorting and filtering as in Datatables.
    This is doable, and my trouble was time related. Once I finish this phase, I will create those custom filters but not now.

    Yah, I already use the custom variables. But ofcourse I have to recreate the AjaxSource.
    In datatables, the url is sent like this:
    www.host.com?var1=val1&var2=val2...etc
    Now, Ez publish has many options to pass variables to the system. It boils down to clean URL and ordered and unordered parameters.
    for example
    Http://www.ez.no/module_custom/view_cust/myFunction/param1/param2/(optional_param1)/Optional_param_val1...etc
    and there is no ? or & in there as per clean urls in Drupal and other CMS systems.

    I saw a template based URL generator sometime ago that works as follows:
    lets say you have:
    http://www.myhost.com///
    what you do is create a map of your internal variables to be sent to hte server, to those param_name1 ..etc
    for exampl
    'iDisplayStart' = 'Offset'
    So, when the request is sent, the generated url will look like
    http://www.myhost.com/offset/val
    ofcourse the '/' can be changed into '='

    Maybe its a bad idea but its very flexible. I saw it used by sendxms.com

    Best Regards,
    Hadi
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Hadi,

    A couple of things here:

    1. Shame you can't bypass the CMS and just access the database directly. That would solve your access and the flexibly problem. But it's not the end of the world I suppose :-)

    2. You can use a custom 'get' function (like in the example I posted) to rewrite the URL in this fashion if you like - nothing to stop that from being a viable form of getting the data. Personally I'm not a fan of this method as it's abusing the URI standards (variables come after a '?' for GET, for example), rather than part of the main locator. But it's certainly do-able with DataTables as it stands!

    Regards,
    Allan
This discussion has been closed.