[ 4 posts ]

Dave McDaniel

  • Username: dam5h
  • Joined: Mon Aug 30, 2010 6:53 am
  • Posts: 50
  • Offline
  • Profile

sorting relationship with editable fields

Post Posted: Tue Nov 02, 2010 6:15 am
+0-
I have sorting enabled on a column and the columns are not "explicitly" set to editable although I do make them one-click editable via my own function. I cannot sort properly after changing these values until I refresh the page. I notice on other columns that I have set an "editor" definition for in the column definitions do not suffer this issue. Is there so extra call that I need to put in my own one click edit function to inform the sorter the value has changed (without doing an entire dataset refresh). I don't want to use an editor because I want to keep my custom one-click method.

Maybe there is a simpler solution where I can set my function up as a custom editor?

Thanks

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: sorting relationship with editable fields

Post Posted: Tue Nov 02, 2010 7:35 am
+0-
Sorting sorts the values stored in the RecordSet. If you use any editor which does not update the underlying field in the RecordSet, sorting will take the original value, not the one seen on the screen, which has not been updated. When using your own editor, do not update the HTML but use method updateCell or updateRow to refresh both, the HTML and the underlying field. If several cells are being edited, you may opt to update the RecordSet directly and then just refresh the screen just in one go, to reduce the number of updates.

When the updated value of a field would make the row appear in a different order, DataTable will not reposition the row because there are several possible ways of handling it and it is up to you.

The first option, some would argue is a bug, is to do nothing, leave the record unsorted. Others suggest moving the records around is too distracting to the user and, since it will necessary take some time, a waste. This is what DataTable does.

The second option is simply to mark the column as no longer sorted which, in fact, is the case. To do that simply set sortedBy to null:

myDataTable.set('sortedBy',null);

I believe this should be the proper behavior, it leaves the row where it was, wastes no time resorting and clearly states that at least one row is out of place.

Besides, when receiving a click on a header of a sortable column, DataTable checks if it is already sorted and if so, it will simply reverses the order of the rows, which is much faster than resorting. The problem is that the misplaced row will remain in the same place to their neighbors, just reversed, and will not be re-sorted. Thus, setting sortedBy to null should be the correct behavior so that a new click on a header cell will really sort the records.

The final option is to resort the whole DataTable, which you are free to do after the new value of the field is saved. To do that, read and save the value of the sortedBy attribute somewhere, set sortedBy to null and call sortColumn using the values read from sortedBy.

Dave McDaniel

  • Username: dam5h
  • Joined: Mon Aug 30, 2010 6:53 am
  • Posts: 50
  • Offline
  • Profile

Re: sorting relationship with editable fields

Post Posted: Tue Nov 02, 2010 8:30 am
+0-
thanks again Satyam, one other question does "myDataTable.set('sortedBy',null);" set the entire data table to non sorted or can you do it just for one column?

i actually was updating the record properly but the sort reverse order speed up thing was my issue.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: sorting relationship with editable fields

Post Posted: Tue Nov 02, 2010 9:54 am
+0-
sortedBy has two properties, the key of the sorted column and the direction. DataTable assumes only one column is sorted at any one time. If you set it to null or set its individual members to null, no column will be marked as sorted. Basically, what it does is to set the visual clues and servers as a status indicator to tell which column is sorted. Setting it will not actually sort anything, it will only make the user and the datatable that it is sorted by one specific column.
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum