Les,
We do this by having a sort order column and then a _javascript_ interface
that lets them move items updown in a list. Then, the list of ordered items
is sent to the action page, and looped through, and we update the sortorder
column based on the new order of the list. We're not dealing with huge
lists, though. The overhead for looping through as many as you're talking
about might negate the benefits of this option.
-Deanna

Here's the _javascript_:
<SCRIPT LANGUAGE="_javascript_" TYPE="text/_javascript_">
<!--
function swapitems(sel,x,y) {
//make sure there's something selected & that it's being moved out of range
if (x != -1 && y < sel.options.length && y >= 0){
temp = new Option(sel.options[x].text,sel.options[x].value,1,1)
temp2 = new Option(sel.options[y].text,sel.options[y].value)
sel.options[x] = temp2; sel.options[y] = temp;

//dump the values for the hidden field
  document.sortform.itemorder.value = "";
//re-populate the hidden field
  for (var i = 0; i < sel.options.length; i++) {
  if (i > 0) {
  document.sortform.itemorder.value += "," + sel.options[i].value;}
  else {
  document.sortform.itemorder.value += sel.options[i].value;}

  }
  }
else
//if they haven't selected an item.
if (x == -1)
{alert("Please select an item to move.");}
//if they try to move the last item down
else if (y >= sel.options.length)
{alert("Sorry, you can't move the last item down.");}
//if they try to move the first item up
else
{alert("Sorry, you can't move the first item up.");}

}

//-->
</SCRIPT>

Here's the form table:
<table cellpadding="3" cellspacing="0" border="0">
<tr>
<td rowspan="2"><select name="myselect"
size="<cfoutput>#sortableUsers.recordcount#</cfoutput>">
<cfoutput query="sortableUsers">
<option name="prsnid" value="#prsnid#">#lastname#, #firstname#</option>
</cfoutput>

</select></td>
<td valign="top"><a href="" document.sortform.myselect;
swapitems(s,s.selectedIndex,s.selectedIndex-1)">Move Up</a></td>
</tr>
<tr>
<td valign="bottom"><a href="" document.sortform.myselect;
swapitems(s,s.selectedIndex,s.selectedIndex+1)">Move Down</a><br></td>
</tr>
</table>

Here's the action page:
<cfloop from="1" to="#listlen(form.itemorder)#" index="i">

   <cfquery datasource="#dsn#" password="#pass#" username="#user#"
name="sortupdate">
    UPDATE projperson
    SET  sort = <cfqueryparam cfsqltype="cf_sql_integer" value="#i#">
    WHERE  projectid = <cfqueryparam cfsqltype="cf_sql_integer"
value="#projectid#">
    AND  prsnid = <cfqueryparam cfsqltype="cf_sql_integer"
value="#listgetat(form.itemorder, i)#">
   </cfquery>

</cfloop>

----- Original Message -----
From: "Les Mizzell" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Friday, October 17, 2003 12:44 PM
Subject: Sort Order Best Practice Request

Here's a problem I've been plagued with recently, and sure others have
as well.

I've got a large number of tables listing industrial parts. There's
columns and columns of specs, temperature tolerances, blah, blah, blah...

I've built an administration system for the client to keep all this
stuff updated, and built display pages that they're pulling into Acrobat
to actually print their catalogue when needed.

However, they need products from each table listed in a specific order
for printing. There's nothing in the database that can be used to sort
these to get them in the order they want - it's completely arbitrary. No
alpha or numeric sort on any combination of columns will actually do the
trick.

So, for a page listing 550 parts from a table, what type of solution or
system can I use that will allow them to specify, on whatever whim, the
exact order all these parts get listed.  They need to be able, for
example, shift product number 15 down to the 25th position and have
everything else resort from there....

You *could* let them manually edit a "sort index", but if you change #5
to #15, then how the heck to you avoid having to manually edit every
other number in the table to sort them all out again, since duplicates
ain't gonna work?

Ideas?
Best practice?
How are others handling this sort (pun!) or thing?

--
Les Mizzell
-------------------------
"Mihi placent, O Pincerna!
  Virent ova! Viret perna!
  Dapem posthac non arcebo.
  Gratum tibi me praebebo."


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to