Loading ...
Sorry, an error occurred while loading the content.
 

Sorting Links in dataTable

Expand Messages
  • Eric
    Hello Group. I have a DataTable created from markup (basically using the progressive enhancement example on the site). One column has links in it, like those:
    Message 1 of 3 , Jul 10, 2008
      Hello Group.

      I have a DataTable created from markup (basically using the progressive enhancement
      example on the site). One column has links in it, like those:

      <a href="some.php?id=17">test link</a>
      <a href="some.php?id=18">another test ink</a>

      As the value of the cell is used as a string "test link" will ever be first and "another test
      link"
      will be second.

      I tried using the following parser which gets rid of the link, but those changes are reflected
      in
      the table itself.

      this.parseLinkFromString = function(sString) {
      return sString.substring(sString.indexOf('>')+1,sString.indexOf('<',2));
      };

      Any Advice?

      Yours, Eric

      --
      Eric Eggert
      http://yatil.de
    • Satyam
      If you parse the link you will loose the URL data so you would not be able to follow through. You could define your own custom sorting function:
      Message 2 of 3 , Jul 10, 2008
        If you parse the link you will loose the URL data so you would not be
        able to follow through. You could define your own custom sorting function:

        http://developer.yahoo.com/yui/datatable/#advancedsort

        so you would still have the full link in each cell.

        Satyam


        Eric wrote:
        > Hello Group.
        >
        > I have a DataTable created from markup (basically using the progressive enhancement
        > example on the site). One column has links in it, like those:
        >
        > <a href="some.php?id=17">test link</a>
        > <a href="some.php?id=18">another test ink</a>
        >
        > As the value of the cell is used as a string "test link" will ever be first and "another test
        > link"
        > will be second.
        >
        > I tried using the following parser which gets rid of the link, but those changes are reflected
        > in
        > the table itself.
        >
        > this.parseLinkFromString = function(sString) {
        > return sString.substring(sString.indexOf('>')+1,sString.indexOf('<',2));
        > };
        >
        > Any Advice?
        >
        > Yours, Eric
        >
        >
      • Eric
        ... That worked out easier than anticipated, my solution for the record: var mySortFunction = function(a, b, desc) { var parseLinkFromString =
        Message 3 of 3 , Jul 10, 2008
          > If you parse the link you will loose the URL data so you would not be
          > able to follow through. You could define your own custom sorting function:
          >
          > http://developer.yahoo.com/yui/datatable/#advancedsort
          >
          > so you would still have the full link in each cell.

          That worked out easier than anticipated, my solution for the record:

          var mySortFunction = function(a, b, desc) {

          var parseLinkFromString = function(sString) {
          // Knowing my content (one link inside the cell,
          // string to sort is the link element's content)
          // extracting the string to sort was easy:
          return sString.substring(sString.indexOf('>')+1,sString.indexOf('<',2));
          };


          // Deal with empty values (From the example)
          if(!YAHOO.lang.isValue(a)) {
          return (!YAHOO.lang.isValue(b)) ? 0 : 1;
          }
          else if(!YAHOO.lang.isValue(b)) {
          return -1;
          }

          // Compare contents of link in one row (variable a) to the
          // other (b). You still need to add the name of your column
          // by hand (here "titel")
          var comp = YAHOO.util.Sort.compare;
          return comp(parseLinkFromString(a.getData("titel")),
          parseLinkFromString(b.getData("titel")), desc);
          };

          Thanks Satyam.


          --
          Eric Eggert
          http://yatil.de
        Your message has been successfully submitted and would be delivered to recipients shortly.