| Page 1 of 1 | [ 10 posts ] |
|
the sort functionality is not working for me after I add a new record or alter the data of an existing record to the data table. when altering i am using "updateCell" function.
it does however begin to work as expected once i click another column to sort then return to original column the sort works fine, just not the very first attempt. it's as if the data isn't being registered until i try to sort at least 2 columns, but i would like the initial sort to work. thanks in advance. |
|
If the value just entered is in a sorted column you have two choices.
a) re-sort the column or b) mark the column as no longer sorted. There are pros and cons for each. Re-sorting the column will probably send the row with the edited cell somewhere else, and if the user is keeping track of where he's at when editing, that will break the sequence. If paging is used, re-sorting might send the row to some other page which, for the user, it means it has disappeared. If the user meant to update other fields in the same row, that will certainly be confusing. Marking the column as no longer sorted is limited more accurate, the row remains in place, the user can see the changes applied and does not get upset by rows moving about. This only requires setting the sortedBy configuration attribute to null. Code: myDataTable.on('editorSaveEvent', function () { myDataTable.set('sortedBy',null); }) |
|
I meant to say that sorting is not working properly until i sort another column first.
for example i am putting a number in a column which is 0 by default, when i change 0 to 3 and hit save the number changes in the cell but if i then go and click the column heading to sort it, the row stays with the 0's and doesn't move into the vicinity of the other "3's". if however, i go sort another column and then come back and sort the number column, it behaves as expected; moving the newly assigned "3" row in with the other "3's". perhaps i need to call some type of reload function after "updateCell" so the altered data is properly recognized by the sort engine? thanks |
|
That is a known issue I forgot about, a pity since I reported it:
http://yuilibrary.com/projects/yui2/ticket/2528949 Since DatatTable does not reset the sortedBy status when a cell is edited, if you try to sort the same column, it assumes it is already sorted and simply reverses the order of the columns, since it is much faster than sorting. So, while you keep clicking the same column, it will simply flip the rows over and over again. When you sort another column and then come back to sorting the column with the edited cell, it will really have to sort it. The ticket contains a patch for this and further information. |
|
thanks very much that fixed part of my issue.
i do still however have an issue when adding a completely new row (rather than just altering a cell in an existing row). after adding a new row, the sort does not work unless i sort at least 2 columns. thanks |
|
nevermind the second question, that issue was fixed by the same method, simply setting the sortBy to null whenever a new record is added to the table.
thanks again. |
|
Hi Satyam,
I am facing the same problem with Sort not working initially on newly added record or when the DataTable record is updated. My DataTable has a DropDownCellEditor control and some other HTML controls(like html TextBox created dynamically using Column formatters). Your solution to make the sortedBy = null in 'editorSaveEvent' fixed partially. It works fine for DropDownCellEditor column If I try to sort the same column after adding/update. It doesn't work the same for other columns as those columns doesn't have any YUI editors like TextBoxCellEditor. Those columns has HTML controls like TextBox. And I think the 'editorSaveEvent' will fire only for YUI cell editors and not for custom editors like HTML text box. Please tell me how to handle the sort the same column after add/update if the DataTable has some custom HTML controls. Thanks |
|
Sorting works on the values stored on the Records in the RecordSet. If you have input controls in your cells you are responsible to store their values into the corresponding fields in their Records so that sort finds the correct values to sort on.
Anyway, it is always required to have values stored in the RecordSet. The HTML produced by the DataTable is volatile, DataTable is free to render the table at anytime based on the values in the RecordSet so those are the only true values you really have the values on the input elements on the screen are volatile. And no, if you put HTML controls on the cells of the DataTable, don't expect the DataTable to know about them. It will not trigger events such as editorSaveEvent since it is not its own editor, it is all up to you. |
|
Then which event, can I put the code 'sortedBy = null' so that the DataTable will know that the column(which has html input control) needs to be sorted again once we sort the same column after add/update?
|
|
Wherever you placed your code to keep your Record in sync with the HTML input control. Whenever you set the field in the Record, there you should reset sortedBy. It very much depends on the type of control you are using and how you want it handled. You want to refresh the Record on every keystroke on an input control or just on leaving it (onBlur)? That is up to you. The rule should be, whenever you call setData() on the Record, then you should reset sortedBy.
Here is a sampler: http://www.satyam.com.ar/yui/2.6.0/asso ... trols.html |
| Page 1 of 1 | [ 10 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group