dataFor: function()

in js/layout/table.js [111:159]


    dataFor: function (el) {
      if (!$.contains(this.el, el)) {
        return undefined;
      }

      var $el = $(el);
      // TODO [akamel] can we use target instead?
      var $tr = $el.closest('tr', this.el);
      var $closestTD = $el.closest('td', this.el);
      var $closestTH = $el.closest('th', this.el);
      var $td = _.size($closestTD) ? $closestTD : $closestTH;
      var virtualizer = this.getRenderer('virtualization');
      var i = $tr.index();
      var j = $td.index();
      // TODO [akamel] 1- check if $td is th; 2- throw if el is neither th or td as it is assumed in this function
      var isHeader = $td.closest('thead', this.el).length;
      var ret = { header: isHeader };

      // we are not in header
      if (isHeader) {
        if (i === 0) {
          ret.property = this.data.select[j];
        } else if (i === 1) {
          ret.property = this.data.subSelect[j];
        } else {
          ret.property = this.data.selectExpand[j];
        }
      } else {
        i += (virtualizer ? virtualizer.first : 0);
        ret.model = this.data.value[i];
        if (this.data.selectExpand) {
          ret.property = this.data.selectExpand[j];
        } else {
          ret.property = this.data.select[j];
        }
      }

      ret.column = this.data.columns[ret.property];
      if (ret.property === this.grid.projection.get('column.checked')) {
        // TODO [akamel] this shouldn't be here
        var checkbox = $el.find('.column-selection');
        if (checkbox.length) {
          ret.checked = checkbox[0].checked;
        }
      }
      ret.grid = this.grid;

      return ret;
    },