Various default features not working.

Various default features not working.

lostogrelostogre Posts: 14Questions: 0Answers: 0
edited May 2009 in General
This is a great plugin! I am still somewhat new to it, and as such and I am having some trouble. I have implemented a page that combines Datatables and Jeditable. Mostly it is working quite well, however, some of the default functions are not working. First, numeric sorting works well until I add a new row, then it reverts to "alphabet" type sorting. I have tried the numeric sorting plugin to no avail. Second, the state saving function doesn't work. If I go forward several pages and edit a record, once the record is saved it reverts to page one. Third, even though I have used the demos.css code and have formatted my code with all of the same id and class names, I cannot get the icons for the sort indicators on the columns to appear. Also, as I am still new to datatables, if you see anything that I could improve, please feel free to let me know. Thanks in advance. Code sample here: http://pastebin.com/m53caeff2

Replies

  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    Hi lostogre,

    A number of questions there - I'll try and separate them out :-)

    1. Numeric sorting until adding a new row - are you using the latest 1.5 beta? There was a time (can't remember off the top of my head) where it would revert to type 'string' when you add a new row - but this has been addressed now.

    2. Custom sorting type - you have "num-html" sorting functions in your Javascript, but nothing telling DataTables to use them. You either need to define that explicitly with aoColumns.sType, or have a type detection function.

    3. State saving - your code doesn't show this feature as enabled. It is off by default, so you need to enable it with bStateSave ( http://datatables.net/usage#bStateSave ). If this fails then check for a cookie with the prefix "SpryMedia_DataTables_"

    4. Styles - What information does Firebug (or something similar) show? Are the image styles applied, and it just can't locate the images, or do you need to modify the selectors to match your HTML?

    Hope this helps,
    Allan
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    1. I have tried it with 1.5 beta and it still reverts to string sorting.

    2. I wondered about explicitly defining that, but I saw nothing about it in the plugin documentation for it. I'll look into that.

    3. I was under the impression that it was enabled by default. http://www.datatables.net/usage -- details for bStateSave. However, I have tried it with explicit enabling and it still doesn't work.

    4. This turned out to be a permissions problem on the server. Oops!

    Thanks for getting back so quickly!
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    I have now applied the sorting function to the column, but firebug shows an error of:

    a is not defined
    http://10.10.0.14/Heritage/index.php
    Line 18

    var x = a.replace( /<.*?>/g, "" );


    Am I missing something? Should a and b be x and y?
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    1. Odd - does your new data match the formatting constrains (i.e. no white space etc). Having a look at my adding rows demo ( http://datatables.net/1.5-beta/examples/api/add_row.html ) it correctly maintains the sorting type.

    2. Perhaps this example will help: http://datatables.net/1.5-beta/examples/api/sorting_plugin.html

    3. Sorry about that - I can see why you were under that impression :-). The documentation for there is out of data (and has been for some time...) I have updated it now to show that the default state is off.

    4. Good stuff.

    Allan
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    I changed x, y in the function definition to a, b and now it works quite well. You may want to update your example source code.
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    Hmm yes - not good. Sorry about that. The plug-in code has now been updated.

    Allan
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    1. I don't see anything different between your code and mine. I looked at the element for the ID column and there is no white space. Since I am now using the plugin, It doesn't matter to me, but I am willing to try to help you get to the bottom of it.

    2. The code at http://datatables.net/1.5-beta/examples/api/sorting_plugin.html shows the same change that I made, changing x,y in the function definition to a, b.

    3. I have now explicitly defined it, and it still doesn't work.
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    No worries about the example code goof. :-)
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    Wow this is a rapid fire conversation :-)

    3. Is the cookie I mentioned created? If not, then that's the problem. If so, then the question is, does it contain valid JSON?
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    Yes, it is. I like it. You are saving me many hours of banging my head on the monitor. A good thing since it is an LCD and I don't think that it would survive.

    3. No, I did not create the cookie. I will try that. I didn't know that it was explicitly required. I reread the documentation and while it mentions the cookie, it doesn't say that it is required.
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    3. In fact the docs for the cookie says that there is a default for 2 hours.
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    3. The cookie need not be created by you - DataTables should do it automatically. Here is my example for state saving: http://datatables.net/1.5-beta/examples/basic_init/state_save.html . This works fine on my browser - how about your own?
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    3. I have now explicitly defined it for one hour and it still doesn't work.
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    3. Yes, your example works. And when I try simply refreshing the page with my code, it also works. I guess it is a strange interaction with Jeditable. What exactly needs to be JSON?
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    I just discovered that it has the same problem when adding a record. If it is not sorted descending, then adding a new record causes it to revert to the first page.
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    3. Ah now - I think there was a little misunderstanding. The state saving feature only works with your reload the page! The information from the cookie is read at page load time and put into the DataTables in place of the default values.

    So what sounds like is happening for you is that on the update the redraw is causing the paging to go back to the start (i.e. when you update the table). This is because DataTables is doing a full redraw when you do the update. The reason for this is that the information in the column being sorted upon might have changed - and therefore a resort is required.

    If you don't want this to happen you can pass "false" as the fourth parameter for fnUpdate ( http://datatables.net/api#fnUpdate ) to tell DataTables not to redraw the table. And hopefully that will do what you are looking for now.

    Allan
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    Ah! Ok. I'll try that. Thanks.
  • lostogrelostogre Posts: 14Questions: 0Answers: 0
    Ok. That took care of edits, but it still does it when adding a new row. Is there any way to display a page using code?
  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    Hi lostogre,

    I think you have two options here:

    1. You can make use of an API function I've just added to the plug-ins page called fnDisplayRow() ( http://datatables.net/plug-ins#api_fnDisplayRow ). This function will take a TR node as a parameter and alter the table's paging to show the row.

    2. fnAddData() also has a 'do not redraw' parameter (pass 'false' as the second parameter). This isn't documented yet as it is only available in 1.5, which is currently in beta.

    Regards,
    Allan
This discussion has been closed.