3.2.0

Sorting hyperlinks

I am trying to sort a column which contains hyperlinks. I believe the sorting is based on the entire string, so it will sort the URL of the link before the actual text of the link.

Is there a graceful way to sort hyperlinks?

Thanks in advance.
Mike
February 25,
Grid uses data/text property for the cell content and data/value for the column sort (to compare cells). By default data/value = data/text. In your case you need to provide clean string into data/value property and formatted (as hyperlink) string into data/text.

obj.setProperty("data/text", function(i,j){return myData[i][j]})
obj.setProperty("data/value", function(i,j){return ...})
Alex (ActiveWidgets)
February 25,
Alex - would you care to finish your example here? I think that I could use it.

many thanks.
Sorting hyperlinks - please finish
October 11,
Let's say you have a hyperlink in a column 2. So the data array will look like

myData = [
  ["cell text", "another cell", "<a href='link.htm'>label text</a>", ...],
  ...
];


To remove <a> tags we can use simple regular expression:

obj.setProperty("data/value", function(i,j){
  if (j==2){
    return myData[i][j].replace(/<.+?>/g, "");
  }
  else {
    return myData[i][j];
  }
})


The opposite approach could seem much more natural - supply values and format them to text just before displaying on the client side. However it has a higher performance cost - you have to format all columns for display but you have to extract values from just one column for sorting.
Alex (ActiveWidgets)
October 11,
Oh that is sooo cool!

Another ActiveWidget wrinkle in my brain!!!
And it sure beats the heck out of the associative array that I was just trying to hook up!

Thanks a bunch Alex - keep up the awesome work!
Michael
October 11,
Hmm, my link looks like this:

<a href='/PublicSearch/ProdDetail1.asp?C=3&SV=&DT=1&CID=121&PID=2'>10/15/2001<\a>
and it doesn't seem to return just the text, in this case, a date.
Michael
October 11,
Update:

It appears as if I was attempting to place an HREF link into the Value/Text property which was specified with a format of 'date'.

That was breaking my code and causing the data to not be displayed.

The resulting code is as follows:

var string = new Active.Formats.String; 
    var number = new Active.Formats.Number; 
    var date = new Active.Formats.Date; 
    //      define formatting rule for text output 
    number.setTextFormat(""); 
    date.setDataFormat("ISO8601"); 
    date.setTextFormat("yyyy-mm-dd"); 
    date.setErrorText(""); 
    date.setErrorValue(-1); 
    var myColumns = ["Company Name", "Product Name", "EPA Reg #", "TIRMS Date", "<img src='/images/icon_pdf_sm.gif'>  Labels", "<img src='/images/icon_pdf_sm.gif'>  MSDS", "<img src='/images/icon_pdf_sm.gif'>  SUPPs", "<img src='/images/icon_pdf_sm.gif'>  TBs"];
    var formats = [string, string, string, date, date, date, date, date]; 
    //	create ActiveWidgets Grid javascript object
    var obj = new Active.Controls.Grid;
    //	set number of rows/columns
    obj.setRowProperty("count", myData.length);
    obj.setColumnProperty("count", 8);
    //      set column formatting 
    obj.setColumnText(function(i){return myColumns[i]}); 
    obj.setColumnHeaderHeight("20px");
    
    obj.setDataText(function(i, j){if ((j==4)||(j==5)||(j==6)||(j==7)){return myData[i][j]; 
  	}else{return formats[j].dataToText(myData[i][j]);}});
  	obj.setDataValue(function(i, j){if ((j==4)||(j==5)||(j==6)||(j==7)){return myData[i][j].replace(/<.+?>/g, ""); 
  	}else{return formats[j].dataToValue(myData[i][j]);}});

    //	write grid html to the page
    document.write(obj);


I specifically had to use

date.setDataFormat("ISO8601"); 
date.setTextFormat("yyyy-mm-dd");


and change the way I was retrieving the data from date columns within a table in SQL Server.

An example of how to get a nicely formatted date which the grid can process and subsequently sort on is:

SELECT CONVERT(CHAR(10),DocumentModifiedDT,126) as 'myDate' from tableName


Will return the date value as yyyy-mm-dd
ie. '2004-10-15'

HTH, as I've spent 3 full days learning how to make this work :-)
Michael
October 12,
i just formatted my links with and id that used the url text and it worked fine... I like keeping it simple

<a id="firstlink" href="whatever" >firstlink</a> and so on.....
Daron
October 13,
Daron,

Right simple is good - however in my case, my link text was a date, and to sort those properly, I needed to do what I posted.
Michael
November 12,

This topic is archived.

See also:


Back to support forum