By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Implement sorting on Ajax response

P: 52
Hi,
I have created a dynamic widget using dojo support.
Now i would like to implement the sorting feature for the changing the display order either by name or status of the computer.Please suggest me.
Expand|Select|Wrap|Line Numbers
  1. function LabMonitor(container_element, lab_identifier){
  2.     var _pause = false;
  3.     var _lab = lab_identifier;
  4.      var _getComputerInfo = function(){
  5.         if (_pause) {
  6.             return;
  7.     }
  8.     dojo.xhrGet({
  9.             url: "php/getComputerInfo.php?lab=" + _lab,
  10.             handleAs: "json",
  11.             timeout: 5000,
  12.             load: function(response, details){
  13.                 _refreshComputerStatus(response);
  14.             },
  15.             error: function(error_msg, details){
  16.                 _handleError(error_msg);
  17.             }
  18.         });
  19.     }
  20.  
  21.     var _computers = new Array();
  22.      var _refreshComputerStatus = function(computer_info){
  23.     var result = "";
  24.  
  25.     for (var i = 0; i < computer_info[_lab].length; i++) {
  26.  
  27.     var computer = computer_info[_lab][i];
  28.     var is_known = false;
  29.  
  30.     for (var j = 0; j < _computers.length; j++) {
  31.                 if (_computers[j].getName() == computer.name) {
  32.                     is_known = true;
  33.                     break;
  34.            };
  35.     }
  36.  
  37.     if (is_known === true) {
  38.      result += "<span class='computer'>"+computer.name+"</span><span class='"+computer.status+"'>"+computer.status+"</span><br/>";
  39.    } else {
  40.                _computers.push({
  41.                name : computer.name,
  42.                getName : function() {
  43.                return this.name;
  44.           }
  45.     });
  46.        result += "<span class='computer'>"+computer.name+"</span><span class='"+computer.status+"'>"+computer.status+"</span><br/>";
  47.         }
  48.  
  49.    }
  50.         var html = "<div class='title'>Monitoring Lab"+ _lab+"</div>";
  51.         html += "<div class='toolbar'>Sortby <input type='radio' value='name' name='sort'/>name <input type='radio' value='status' name='sort'/>status</div>"; 
  52.         html += "<div id='results"+_lab+"'>"+result +"</div>";
  53.         container_element.innerHTML = html;
  54.  
  55.  
  56. }
  57.  
  58.  
  59.         pause =  function() {
  60.             _pause = true;
  61.         };
  62.         unpause = function() {
  63.             _pasue = false;
  64.         };
  65.         var _handleError = function(){
  66.      }
  67.     setInterval(_getComputerInfo, 3000);
  68. }
  69.  
Mar 31 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.