(no subject)
Trevor DeVore
lists at mangomultimedia.com
Mon May 4 08:57:27 EDT 2009
On May 2, 2009, at 11:05 PM, Shao Sean wrote:
> modified it some to be a little cleaner as well as allowing the data
> grid to know that it is sorting on the custom sorted column..
In the current release version of the data grid there are two issues
when performing a custom sort within SortDataGridColumn.
The first is that you can't set the dgIndexes property in order to
change the sort of the indexes. This doesn't affect your example
because you seem to be storing "size" as a hidden column in your table
and then using SortDataByKey to do the sort.
The second issue is that there is no easy way of updating the internal
props and UI to reflect the currently sorted column.
I've uploaded a test build of the library (1.0 build 8) which
addresses these issues. You can now set the dgIndexes property and I
created a handler out of existing data grid code that updates internal
props and UI: HiliteAndStoreSortByColumn. HiliteAndStoreSortByColumn
is meant to be called from within SortDataGridColumn when you are
performing a custom sort.
I also switched the sorting so that it occurs on mouseup rather than
mousedown.
<http://www.bluemangolearning.com/download/revolution/tools/revdatagridlibrary.rev.zip
>
Here is an example of using HiliteAndStoreSortByColumn and dgIndexes
in on SortDataGridColumn. Note that this is only required if you are
performing a custom sort.
on SortDataGridColumn pColumn
switch pColumn
case "MySpecialColumn"
## Update UI and 'sort by column'
HiliteAndStoreSortByColumn "MySpecialColumn"
## Get ready to perform custom sort.
put the dgIndexes of me into theIndexes -- so we
perform a stable sort
put the dgData of the dgControl of me into theDataA
-- get data so we can create sort list
## Create list of indexes and the key to sort by
repeat for each item theIndex in theIndexes
put theIndex & tab & theDataA[theIndex]
["MySpecialColumn"] & cr after theData
end repeat
delete the last char of theData
## At this point you can apply your special sort
function to item 2 to -1 of theData
## Now update the indexes of the data grid so new
order is reflected.
put empty into theIndexes
repeat for each line theLine in theData
put item 1 of theLine & comma after theIndexes
end repeat
delete the last char of theIndexes
## Setting the dgIndexes will update the sort order
and redraw data.
set the dgIndexes of the dgControl of me to theIndexes
break
default
pass SortDataGridColumn
end switch
end SortDataGridColumn
Here are some notes to your sort handler.
> command sortDataGridColumn pColumn
> constant kColumnSize = "size"
> local tOldSortKey
> lock screen
>
> switch (pColumn)
> case kColumnSize
> lock messages
> put the dgProps["sort by column"] of me into tOldSortKey
## Note: You no longer need to set the 'sort by column' here. It is
set in HiliteAndStoreSortByColumn
> set the dgProps["sort by column"] of me to kColumnSize
>
## Note: This code a) won't work and b) has already been handled at
this point.
## A) because you have messages locked and
dgColumnSortDirection is a custom property using get/setProp.
## B) Changing of ascending/descending is handled when you
click on the column header. This happens before
## SortDataGRidColumn is called.
> if (the dgColumnSortDirection[kColumnSize] of me = "ascending")
> then
> set the dgColumnSortDirection[kColumnSize] of me to
> "descending"
> else
> set the dgColumnSortDirection[kColumnSize] of me to "ascending"
> end if
> unlock messages
## Note: FYI: I believe this gives you the exact same behavior as
setting the column sort to "numeric" in the property inspector.
## based on the code you aren't doing anything differently.
> sortDataByKey kColumnSize, "numeric", the
> dgColumnSortDirection[kColumnSize] of me, FALSE
>
## Note: this is no longer needed with HiliteAndStoreSortByColumn.
> set the dgHilite of group tOldSortKey of group "dgHeader" to
> FALSE
> set the dgHilite of group kColumnSize of group "dgHeader" to TRUE
> break
> default
> pass sortDataGridColumn
> break
> end switch
> end sortDataGridColumn
Here is an example of SortDataGridColumn using updated data grid
library:
on SortDataGridColumn pColumn
constant kColumnSize = "size"
switch pColumn
case kColumnSize
HiliteAndStoreSortByColumn kColumnSize
SortDataByKey kColumnSize, "numeric", the
dgColumnSortDirection[kColumnSize] of me, FALSE
break
default
pass SortDataGridColumn
end switch
end SortDataGridColumn
Regards,
--
Trevor DeVore
Blue Mango Learning Systems
ScreenSteps: http://www.screensteps.com
Developer Resources: http://revolution.bluemangolearning.com
More information about the use-livecode
mailing list