dojox/data/HtmlTableStore.js

  • Provides:

    • dojox.data.HtmlTableStore
  • dojox.data.HtmlTableStore

    • type
      Function
    • parameters:
      • args: (typeof Object)
    • source: [view]
        dojo.deprecated("dojox.data.HtmlTableStore", "Please use dojox.data.HtmlStore");
        // summary:
        //  Initializer for the HTML table store.
        // description:
        //  The HtmlTableStore can be created in one of two ways: a) by parsing an existing
        //  table DOM node on the current page or b) by referencing an external url and giving
        //  the id of the table in that page. The remote url will be parsed as an html page.
        //
        //  The HTML table should be of the following form:
        //  
        //   
        //    
        //     
        //     
        //    
        //   
        //   
        //    
        //     
        //     
        //    
        //    
        //     
        //     
        //    
        //   
        //  
      Attribute1Attribute2
      Value1.1Value1.2
      Value2.1Value2.2

        //
        // args:
        //  An anonymous object to initialize properties. It expects the following values:
        //  tableId: The id of the HTML table to use.
        //  OR
        //  url:  The url of the remote page to load
        //  tableId: The id of the table element in the remote page

        
        if(args.url){
         if(!args.tableId)
          throw new Error("dojo.data.HtmlTableStore: Cannot instantiate using url without an id!");
         this.url = args.url;
         this.tableId = args.tableId;
        }else{
         if(args.tableId){
          this._rootNode = dojo.byId(args.tableId);
          this.tableId = this._rootNode.id;
         }else{
          this._rootNode = dojo.byId(this.tableId);
         }
         this._getHeadings();
         for(var i=0; i    this._rootNode.rows[i].store = this;
         }
        }
    • mixins:
      • dojo.data.util.simpleFetch: (prototype)
    • summary
  • dojox.data.HtmlTableStore.url

    • tags: public
    • type
      string
    • summary
      The URL from which to load an HTML document for data loading
  • dojox.data.HtmlTableStore.tableId

    • tags: public
    • type
      string
    • summary
      The id of the table to load as store contents.
  • dojox.data.HtmlTableStore._getHeadings

    • type
      Function
    • source: [view]
        this._headings = [];
        dojo.forEach(this._rootNode.tHead.rows[0].cells, dojo.hitch(this, function(th){
         this._headings.push(dojox.xml.parser.textContent(th));
        }));
    • summary
      Function to load the attribute names from the table header so that the
      attributes (cells in a row), can have a reasonable name.
  • dojox.data.HtmlTableStore._getAllItems

    • type
      Function
    • source: [view]
        var items = [];
        for(var i=1; i   items.push(this._rootNode.rows[i]);
        }
        return items; //array
    • summary
      Function to return all rows in the table as an array of items.
    • returns
      array
  • dojox.data.HtmlTableStore._assertIsItem

    • type
      Function
    • parameters:
      • item: (typeof item)
        The item to test for being contained by the store.
    • source: [view]
        if(!this.isItem(item)){
         throw new Error("dojo.data.HtmlTableStore: a function was passed an item argument that was not an item");
        }
    • summary
      This function tests whether the item passed in is indeed an item in the store.
  • dojox.data.HtmlTableStore._assertIsAttribute

    • type
      Function
    • parameters:
      • attribute: (typeof String)
        The attribute to test for being contained by the store.
    • source: [view]
        if(typeof attribute !== "string"){
         throw new Error("dojo.data.HtmlTableStore: a function was passed an attribute argument that was not an attribute name string");
         return -1;
        }
        return dojo.indexOf(this._headings, attribute); //int
    • summary
      This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
    • return_summary
      Returns the index (column) that the attribute resides in the row.
    • returns
      int
  • dojox.data.HtmlTableStore.getValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • defaultValue: (typeof value)
    • source: [view]
        var values = this.getValues(item, attribute);
        return (values.length > 0)?values[0]:defaultValue; //Object || int || Boolean
    • summary
      See dojo.data.api.Read.getValue()
    • returns
      Object || int || Boolean
  • dojox.data.HtmlTableStore.getValues

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        this._assertIsItem(item);
        var index = this._assertIsAttribute(attribute);


        if(index>-1){
         return [dojox.xml.parser.textContent(item.cells[index])] ;
        }
        return []; //Array
    • summary
      See dojo.data.api.Read.getValues()
    • returns
      Array
  • dojox.data.HtmlTableStore.getAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        this._assertIsItem(item);
        var attributes = [];
        for(var i=0; i   if(this.hasAttribute(item, this._headings[i]))
          attributes.push(this._headings[i]);
        }
        return attributes; //Array
    • summary
      See dojo.data.api.Read.getAttributes()
    • returns
      Array
  • dojox.data.HtmlTableStore.hasAttribute

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        return this.getValues(item, attribute).length > 0;
    • summary
      See dojo.data.api.Read.hasAttribute()
  • dojox.data.HtmlTableStore.containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • value: (typeof anything)
    • source: [view]
        var regexp = undefined;
        if(typeof value === "string"){
         regexp = dojo.data.util.filter.patternToRegExp(value, false);
        }
        return this._containsValue(item, attribute, value, regexp); //boolean.
    • summary
      See dojo.data.api.Read.containsValue()
    • returns
      boolean.
  • dojox.data.HtmlTableStore._containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
        The data item to examine for attribute values.
      • attribute: (typeof attribute-name-string)
        The attribute to inspect.
      • value: (typeof anything)
        The value to match.
      • regexp: (typeof RegExp)
        Optional regular expression generated off value if value was of string type to handle wildcarding.
        If present and attribute values are string, then it can be used for comparison instead of 'value'
    • source: [view]
        var values = this.getValues(item, attribute);
        for(var i = 0; i < values.length; ++i){
         var possibleValue = values[i];
         if(typeof possibleValue === "string" && regexp){
          return (possibleValue.match(regexp) !== null);
         }else{
          //Non-string matching.
          if(value === possibleValue){
           return true; // Boolean
          }
         }
        }
        return false; // Boolean
    • summary
      Internal function for looking at the values contained by the item.
    • description
      Internal function for looking at the values contained by the item.  This
      function allows for denoting if the comparison should be case sensitive for
      strings or not (for handling filtering cases where string case should not matter)
    • returns
      Boolean
  • dojox.data.HtmlTableStore.isItem

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        if(something && something.store && something.store === this){
         return true; //boolean
        }
        return false; //boolean
    • summary
      See dojo.data.api.Read.isItem()
    • returns
      boolean
  • dojox.data.HtmlTableStore.isItemLoaded

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        return this.isItem(something);
    • summary
      See dojo.data.api.Read.isItemLoaded()
  • dojox.data.HtmlTableStore.loadItem

    • type
      Function
    • parameters:
      • keywordArgs: (typeof Object)
    • source: [view]
        this._assertIsItem(keywordArgs.item);
    • summary
      See dojo.data.api.Read.loadItem()
  • dojox.data.HtmlTableStore._fetchItems

    • type
      Function
    • parameters:
      • request: (typeof A)
        request object
      • fetchHandler: (typeof A)
        function to call for fetched items
      • errorHandler: (typeof A)
        function to call on error
    • source: [view]
        if(this._rootNode){
         this._finishFetchItems(request, fetchHandler, errorHandler);
        }else{
         if(!this.url){
          this._rootNode = dojo.byId(this.tableId);
          this._getHeadings();
          for(var i=0; i     this._rootNode.rows[i].store = this;
          }
         }else{
          var getArgs = {
            url: this.url,
            handleAs: "text"
           };
          var self = this;
          var getHandler = dojo.xhrGet(getArgs);
          getHandler.addCallback(function(data){
           var findNode = function(node, id){
            if(node.id == id){
             return node; //object
            }
            if(node.childNodes){
             for(var i=0; i        var returnNode = findNode(node.childNodes[i], id);
              if(returnNode){
               return returnNode; //object
              }
             }
            }
            return null; //null
           }


           var d = document.createElement("div");
           d.innerHTML = data;
           self._rootNode = findNode(d, self.tableId);
           self._getHeadings.call(self);
           for(var i=0; i      self._rootNode.rows[i].store = self;
           }
           self._finishFetchItems(request, fetchHandler, errorHandler);
          });
          getHandler.addErrback(function(error){
           errorHandler(error, request);
          });
         }
        }
    • summary
      Fetch items (XML elements) that match to a query
    • description
      If '_fetchUrl' is specified, it is used to load an XML document
      with a query string.
      Otherwise and if 'url' is specified, the XML document is
      loaded and list XML elements that match to a query (set of element
      names and their text attribute values that the items to contain).
      A wildcard, "*" can be used to query values to match all
      occurrences.
      If '_rootItem' is specified, it is used to fetch items.
    • returns
      object|null
    • chains:
      • self._getHeadings: (call)
  • dojox.data.HtmlTableStore._finishFetchItems

    • type
      Function
    • parameters:
      • request: (typeof )
      • fetchHandler: (typeof )
      • errorHandler: (typeof )
    • source: [view]
        var items = null;
        var arrayOfAllItems = this._getAllItems();
        if(request.query){
         var ignoreCase = request.queryOptions ? request.queryOptions.ignoreCase : false;
         items = [];


         //See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
         //same value for each item examined. Much more efficient.
         var regexpList = {};
         var value;
         var key;
         for(key in request.query){
          value = request.query[key]+'';
          if(typeof value === "string"){
           regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
          }
         }


         for(var i = 0; i < arrayOfAllItems.length; ++i){
          var match = true;
          var candidateItem = arrayOfAllItems[i];
          for(key in request.query){
           value = request.query[key]+'';
           if(!this._containsValue(candidateItem, key, value, regexpList[key])){
            match = false;
           }
          }
          if(match){
           items.push(candidateItem);
          }
         }
         fetchHandler(items, request);
        }else{
         // We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort
         // of the internal list so that multiple callers can get listsand sort without affecting each other.
         if(arrayOfAllItems.length> 0){
          items = arrayOfAllItems.slice(0,arrayOfAllItems.length);
         }
         fetchHandler(items, request);
        }
    • summary
      Internal function for processing the passed in request and locating the requested items.
  • dojox.data.HtmlTableStore.getFeatures

    • type
      Function
    • source: [view]
        return {
         'dojo.data.api.Read': true,
         'dojo.data.api.Identity': true
        };
    • summary
      See dojo.data.api.Read.getFeatures()
  • dojox.data.HtmlTableStore.close

    • type
      Function
    • parameters:
      • request: (typeof dojo.data.api.Request || keywordArgs || null)
    • source: [view]
        // summary:
        //  See dojo.data.api.Read.close()
        // nothing to do here!
    • summary
      See dojo.data.api.Read.close()
      nothing to do here!
  • dojox.data.HtmlTableStore.getLabel

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        if(this.isItem(item))
         return "Table Row #" + this.getIdentity(item);
        return undefined;
    • summary
      See dojo.data.api.Read.getLabel()
  • dojox.data.HtmlTableStore.getLabelAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return null;
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.HtmlTableStore.getIdentity

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        this._assertIsItem(item);
        //Opera doesn't support the sectionRowIndex,
        //So, have to call the indexOf to locate it.
        //Blah.
        if(!dojo.isOpera){
         return item.sectionRowIndex; // int
        }else{
         return (dojo.indexOf(this._rootNode.rows, item) - 1) // int
        }
    • summary
      See dojo.data.api.Identity.getIdentity()
    • returns
      int
  • dojox.data.HtmlTableStore.getIdentityAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
         return null;
    • summary
      See dojo.data.api.Identity.getIdentityAttributes()
      Identity isn't taken from a public attribute.
  • dojox.data.HtmlTableStore.fetchItemByIdentity

    • type
      Function
    • parameters:
      • keywordArgs: (typeof )
    • source: [view]
        var identity = keywordArgs.identity;
        var self = this;
        var item = null;
        var scope = null;


        if(!this._rootNode){
         if(!this.url){
          this._rootNode = dojo.byId(this.tableId);
          this._getHeadings();
          for(var i=0; i     this._rootNode.rows[i].store = this;
          }
          item = this._rootNode.rows[identity+1];
          if(keywordArgs.onItem){
           scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
           keywordArgs.onItem.call(scope, item);
          }


         }else{
          var getArgs = {
            url: this.url,
            handleAs: "text"
           };
          var getHandler = dojo.xhrGet(getArgs);
          getHandler.addCallback(function(data){
           var findNode = function(node, id){
            if(node.id == id){
             return node; //object
            }
            if(node.childNodes){
             for(var i=0; i        var returnNode = findNode(node.childNodes[i], id);
              if(returnNode){
               return returnNode; //object
              }
             }
            }
            return null; //null
           }
           var d = document.createElement("div");
           d.innerHTML = data;
           self._rootNode = findNode(d, self.tableId);
           self._getHeadings.call(self);
           for(var i=0; i      self._rootNode.rows[i].store = self;
           }
           item = self._rootNode.rows[identity+1];
           if(keywordArgs.onItem){
            scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
            keywordArgs.onItem.call(scope, item);
           }
          });
          getHandler.addErrback(function(error){
           if(keywordArgs.onError){
            scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
            keywordArgs.onError.call(scope, error);


           }
          });
         }
        }else{
         if(this._rootNode.rows[identity+1]){
          item = this._rootNode.rows[identity+1];
          if(keywordArgs.onItem){
           scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
           keywordArgs.onItem.call(scope, item);
          }
         }
        }
    • summary
      See dojo.data.api.Identity.fetchItemByIdentity()
    • returns
      object|null
    • chains:
      • keywordArgs.onItem: (call)
      • self._getHeadings: (call)
      • keywordArgs.onError: (call)
  • dojox.data.HtmlTableStore._headings

    • summary
  • dojox.data.HtmlTableStore._rootNode

    • summary
  • dojox.data

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary