Sortable Table Field

Chipp Walters chipp at chipp.com
Wed May 2 23:03:48 EDT 2007


Bridger,

Here's how you can use altFldHeader to sort your 'columns'.
altFldHeader has customProps for each column 'button'. One is called
"altEnableBtn" and if you want a column button to do something, you need to
set the altEnableBtn of the button to true.

Next, if you want to do something OTHER than an alphabetic sort, create a
custom prop for the button called "altSortType", then handle it in the
provided altFldHeaderSort script below.

First, edit the script of the altFldHeader group and insert the following
JUST BEFORE THE pass mouseUp:

  if the altEnableBtn of the target is true then
    altFldHeaderSort the long ID of me,the short name of the target
  end if

Next, drop this script into one of your libraries (or the stack script, or
even the group script if you wish). Edit the script to handle different
types of sorts. HTH, -Chipp

on altFldHeaderSort pWhichAltFldHeader,pWhichColumn
  --> SET pWhichColumn TO "" AND IT CLEARS THE HILITE COLOR
  --> CALLED FROM altFldHeader
  --> FIGURE OUT WHICH COLUMN
  repeat with tCol=1 to the number of buttons in pWhichAltFldHeader
    set the foreColor of button tCol of pWhichAltFldHeader to the effective
foreColor of pWhichAltFldHeader
    if the short name of button tCol of pWhichAltFldHeader is pWhichColumn
then
      put the altSortType of button tCol of pWhichAltFldHeader into
tSortType
      put the longID of button tCol of pWhichAltFldHeader into tBtnID
      set the foreColor of button tCol to blue
      put tCol into tColNum
    end if
  end repeat

  if pWhichColumn is "" then exit altFldHeaderSort
  --> YOU CAN HANDLE SORT TYPES BELOW
  if tSortType is "" then put "text" into tSortType

  put the altTargetField of pWhichAltFldHeader into tFld
  put the htmlText of fld tFld into tHtml
  replace "	" with tab in tHtml
  set itemDel to tab
  put "sort lines of tHtml ascending " & tSortType & " by item " & tColNum &
" of each" into tDo
  do tDo
  replace tab with "	" in tHtml
  set the htmlText of fld tFld to tHtml
end altFldHeaderSort



More information about the use-livecode mailing list