Show And Tell Thursday: Dynamic Sorting Of Data On A Document...
Category Show And Tell Thursday
Some time back, I inherited an application that tracked milestones on a project. Each milestone line contained milestone name, start date, original planned end date, current end date, and actual end date fields. Not so bad, except there were 70 lines of this data! Five fields times 70 lines... 350 fields! The only redeeming factor is how the fields were named... Milestone_0, Milestone_1, and so on up through Milestone_69. At least you could access them programmatically.
Now the users made a request that really worried me. They wanted to be able to sort the 70 lines of data on any one of the five field values. So if they wanted the list to be sorted in start date order, all the data on the document needed to be rewritten in those 350 fields in the proper order... What to do?
What I ended up doing was somewhat creative (for me, at least!). I would ask the user to specify which column should be the sort value, and then I would build an array of that data concatentated by a caret ( ^ ). The lead value in the array element would be the value found in the specified sort column, followed by the five fields in each line. I then used a sort routine stolen from somewhere that would sort an array. Since my sort value was at the front of the array, the sorting was no problem. Once the array was sorted into the new order, I simply read the array and replaced the field values. Voila... dynamic sorting at the user's request!
Here's the code I used to accomplish this hack...
Some time back, I inherited an application that tracked milestones on a project. Each milestone line contained milestone name, start date, original planned end date, current end date, and actual end date fields. Not so bad, except there were 70 lines of this data! Five fields times 70 lines... 350 fields! The only redeeming factor is how the fields were named... Milestone_0, Milestone_1, and so on up through Milestone_69. At least you could access them programmatically.
Now the users made a request that really worried me. They wanted to be able to sort the 70 lines of data on any one of the five field values. So if they wanted the list to be sorted in start date order, all the data on the document needed to be rewritten in those 350 fields in the proper order... What to do?
What I ended up doing was somewhat creative (for me, at least!). I would ask the user to specify which column should be the sort value, and then I would build an array of that data concatentated by a caret ( ^ ). The lead value in the array element would be the value found in the specified sort column, followed by the five fields in each line. I then used a sort routine stolen from somewhere that would sort an array. Since my sort value was at the front of the array, the sorting was no problem. Once the array was sorted into the new order, I simply read the array and replaced the field values. Voila... dynamic sorting at the user's request!
Here's the code I used to accomplish this hack...



Comments
Posted by Duffbert At 07:37:17 On 17/02/2006 | - Website - |
If this was in ND6, I would have used formula. Personally I always like formula when working with list, because Lotus makes it so easy to work with them like the @Sort function. The code would have had 2 @For loops (one to build the list and the other to extra the data from the list) and the use of @Sort between the for loops.
Posted by Chad Schelfhout At 06:59:35 On 17/02/2006 | - Website - |