Results 1 to 2 of 2

Thread: RSSFeedsDisplayer descending alphabetical order

  1. #1
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default RSSFeedsDisplayer descending alphabetical order

    1) Script Title: RSSFeedsDisplayer

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...sdisplayer.htm

    3) Describe problem:

    Hi,
    You wrote:
    To your question, sort by label is based on the ascending alphabetical order of the labels. I reckon you're asking how to sort by descending alphabetical order instead? If so, try finding the below line inside the .js file, and add to it the line in red:

    gfeedfetcher._sortarray(feeds, this.sortstring)
    feeds.reverse()


    Here is the code I've got in the .js file:


    Code:
    gfeedfetcher._sortarray=function(arr, sortstr){
    	var sortstr=(sortstr=="label")? "ddlabel" : sortstr 
    	if (sortstr=="title" || sortstr=="ddlabel"){ 
    		arr.sort(function(a,b){
    		var fielda=a[sortstr].toLowerCase()
    		var fieldb=b[sortstr].toLowerCase()
    		return (fielda<fieldb)? -1 : (fielda>fieldb)? 1 : 0
    		})
    	}
    	else{ //else, sort by "publishedDate" property (using error handling, as "publishedDate" may not be a valid date str if an error has occured while getting feed
    		try{
    			arr.sort(function(a,b){return new Date(b.publishedDate)-new Date(a.publishedDate)})
    		}
    		catch(err){}
    	}
    }
    Please advise what it should look like with the line in red. Appreciate it !
    irina

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmm can you cite the thread I had originally posted that in? But just based on the code you posted, you might try throwing in the line in red here:

    Code:
    gfeedfetcher._sortarray=function(arr, sortstr){
    	arr.reverse()
    	var sortstr=(sortstr=="label")? "ddlabel" : sortstr 
    	if (sortstr=="title" || sortstr=="ddlabel"){ 
    		arr.sort(function(a,b){
    		var fielda=a[sortstr].toLowerCase()
    		var fieldb=b[sortstr].toLowerCase()
    		return (fielda<fieldb)? -1 : (fielda>fieldb)? 1 : 0
    		})
    	}
    	else{ //else, sort by "publishedDate" property (using error handling, as "publishedDate" may not be a valid date str if an error has occured while getting feed
    		try{
    			arr.sort(function(a,b){return new Date(b.publishedDate)-new Date(a.publishedDate)})
    		}
    		catch(err){}
    	}
    }
    DD Admin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •