Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Generate a Link That Sorts a View
 
  chubbard posted this script:
  This function takes a sort field name parameter, and generates a new query string for a link that acts similar to clicking on the fields caption link in the grid view:

webcall function GenSortQuery(strField, bDynamic)
    {
    var arrFilt = request.getFilterString().split('&');
    var strFilt = "";
    var strSort = "";
    for (var i = 0; i < arrFilt.length; i++)
        {
        if (arrFilt[i].substring(0, 6) == "_sort=")
            strSort = arrFilt[i].substring(6, arrFilt[i].length);
        else if (arrFilt[i] != "")
            strFilt += arrFilt[i] + "&";
        }

    if (!bDynamic || strSort == "")
        strSort = strField;
    else
        {
        var arrSort = strSort.split(",");
        if (arrSort[0] == str)
            strSort = "-" + str;
        else if (arrSort[0] == "-" + str)
            strSort = str;
        else
            strSort = str + "," + arrSort[0];
        }
    strFilt += "_sort=" + strSort;
    return strFilt;
    }

Usage inside a view might looks something like:

<a href="?#GenSortQuery('CategoryName')#">Sort by Category Name</a>

to force a descending sort on CategoryName or

<a href="?#GenSortQuery('CategoryName', true)#">Sort by Category Name</a>

for a link with the same sort toggling behavior as the default caption links.
 
  on 2001-08-09 19:45:50, chubbard responded:
  Just wanted to thank Brendan for this. I'm using it to sort multiple fields at once, as in:

?#GenSortQuery('Zip,Street,StreetNo,Firm')#

Works great and solved an important problem in our app.

Thanks again,

Scott
 
  on 2001-08-31 16:33:31, chubbard responded:
  Just informed by KevinNicholls that the 'bDynamic' section of the script above is broken, because I forgot to update all occurances of 'str' with 'strField'.  Below it a fully functional version of the script, with no debugging necessary.

webcall function GenSortQuery(strField, bDynamic)
    {
    var arrFilt = request.getFilterString().split('&');
    var strFilt = "";
    var strSort = "";
    for (var i = 0; i < arrFilt.length; i++)
        {
        if (arrFilt[i].substring(0, 6) == "_sort=")
            strSort = arrFilt[i].substring(6, arrFilt[i].length);
        else if (arrFilt[i] != "")
            strFilt += arrFilt[i] + "&";
        }

    if (!bDynamic || strSort == "")
        strSort = strField;
    else
        {
        var arrSort = strSort.split(",");
        if (arrSort[0] == strField)
            strSort = "-" + strField;
        else if (arrSort[0] == "-" + strField)
            strSort = strField;
        else
            strSort = strField + "," + arrSort[0];
        }
    strFilt += "_sort=" + strSort;
    return strFilt;
    }
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us