Solved

Coldfusion  and MS SQL Order By and Save Sort Order

Posted on 2008-06-18
3
318 Views
Last Modified: 2009-08-07
I have some Coldfusion code that outputs a directory. My challenge is to have three options to sort by. I have a integer field sortorder in the table. It already has a value on how to sort the records. I have a javascript drop down with the three options to sort by. All sort by options are fields in the table. Two of the fields are varchar the names are DIVISION and DEPT. The third is a integer field SORTORDER. When I sort by DIVISION I want it to change the SORTORDER integer field in ascending number order no matter what sortorder number was given when the record was added.
0
Comment
Question by:smares323
  • 2
3 Comments
 
LVL 2

Expert Comment

by:adobe116
ID: 21818942
Hey, if you are still having this problem, can you post your code?  It would make it easier to answer I believe.  For instance, how are you displaying the grid (table)?  Are you using cfgrid?  Are you using client-side sorting or server-side, etc..

If you want a quick solution, check out cfgrid.  Attached is the sample code (modified a bit) from the CFDocs.  Or else http://developer.yahoo.com/yui/datatable/ is good if you know a bit of js.  Otherwise if you post your code I can help more..
    <cfgrid 

        name = "FirstGrid" 

        width = "500"

        query = "DIRECTORY_VARIABLE_HERE" colheaderbold="Yes"

        rowHeaders = "No" >

        

        <!--- cfgridcolumn tags arrange the table and control the display. --->

        <!--- select="No" does not seem to have any effect!!! --->

        <cfgridcolumn name = "VARIABLE_NAMES_HERE" header = "Department" Select="No" width="75"

            textcolor="blue" bold="Yes">

        <cfgridcolumn name = "CorNumber" header = "Course ##" Select="No" width="65">

        <cfgridcolumn name = "CorName" header = "Name" width="125">

        <cfgridcolumn name = "CorLevel" header = "Level" width="85">

        <cfgridcolumn name = "CorDesc" header = "Description" width="125">

    </cfgrid>

Open in new window

0
 

Author Comment

by:smares323
ID: 21819077
We are running Coldfusion MX7. Does the cfgrid tag work with Coldfusion mx7
0
 
LVL 2

Accepted Solution

by:
adobe116 earned 500 total points
ID: 21819200
unfortunately not in html format.  Does Flash though... The cf AJAX scripts were all based on a real early version of yui.
If you 've never checked out the yui library, it's pretty cool.  I used it to output a qry, allow the user to edit each field, and then pass the data back and it didn't take long at all.

here is their basic example:
http://developer.yahoo.com/yui/examples/datatable/dt_basic.html
The data for the table is here (you only need the small bookOrders part):
http://developer.yahoo.com/yui/examples/datatable/assets/js/data.js

Your code would be something like what I have below..

Believe me, if it looks confusing it is really not.  If you don't know scripting or OO languages it can be freaky... but you can just look at the <b>key:"varName"</b> fields and substitute your variables.  And then remove formatters if you don't want them (but you probably will).

If you know js and are familiar with yui, I also combined this example in the code:
http://developer.yahoo.com/yui/examples/datatable/dt_clientsorting.html
It sorts on state, then areacode.

Best of luck, sorry I couldn't be more of a help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">
 

<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.5.2/build/fonts/fonts-min.css" />

<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.5.2/build/datatable/assets/skins/sam/datatable.css" />

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/dragdrop/dragdrop-min.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/element/element-beta-min.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/datasource/datasource-beta-min.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/datatable/datatable-beta-min.js"></script>
 

</head>
 

<body class=" yui-skin-sam">
 

<div id="basic"></div>
 

<script type="text/javascript">

YAHOO.example.Data = {

    bookorders: [

        <!--- STATIC DATA (COMMENTED OUT BUT KEPT SO YOU CAN SEE WHAT WOULD HAPPEN)

        {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"},

        {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"},

        {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"},

        {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"}

         --->

         <!--- YOUR DATA (the extra comma at the end of every loop is ok)--->

         <CFLOOP query name="yourQry">

         {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"},

         </cfloop>

    ]

};

    

YAHOO.util.Event.addListener(window, "load", function() {

    YAHOO.example.Basic = new function() {

        var myColumnDefs = [

            <!--- THIS COL IS RESIZABLE AND SORTABLE --->

            {key:"id", sortable:true, resizeable:true},

            <!--- THIS COL HAS THE DATE FORMATTED USING THE YUI DATE FORMATTER --->

            <!--- THE SORTOPTIONS VARIABLE INDICATES THAT WE SHOULD SORT THE QTY FIELD AFTER THE DATE FIELD (like you wanted) --->

            {key:"date", formatter:YAHOO.widget.DataTable.formatDate, sortable:true, sortOptions:{sortFunction:this.sortDateThenQty},resizeable:true},

            {key:"quantity", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true, resizeable:true},

            {key:"amount", formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true, resizeable:true},

            {key:"title", sortable:true, resizeable:true}

        ];
 

        this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.bookorders);

        this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;

        this.myDataSource.responseSchema = {

            fields: ["id","date","quantity","amount","title"]

        };

        

        this.sortDateThenQty = function(a, b, desc) {

            // Deal with empty values

            if(!YAHOO.lang.isValue(a)) { return (!YAHOO.lang.isValue(b)) ? 0 : 1; }

            else if(!YAHOO.lang.isValue(b)) { return -1; }
 

            // First compare by Date

            var comp = YAHOO.util.Sort.compare;

            var compDate = comp(a.getData("date"), b.getData("date"), desc);
 

            // If dates are equal, then compare by Qty

            return (compDate !== 0) ? compDate : comp(a.getData("quantity"), b.getData("quantity"), desc);

        };

        

        this.myDataTable = new YAHOO.widget.DataTable("basic",

                myColumnDefs, this.myDataSource, {caption:"DataTable Caption"});

    };

});

</script>
 
 

</body>

</html>

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now