Re: problems when setting tableModel at runtime

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: problems when setting tableModel at runtime

kanugula

I was thinking about setting cellrenderer at runtime just after my remote
table is rendered.

I need to compare the cell value with the previous row's cell value. If
there is a difference, I need to high light both of them in red color. This
should happen for all visible rows in the Remote Table

Can somebody give me some hints on how to do that?. I have some 15 columns.

Thanks.
Kanugula.


Derrell Lipman wrote:

>
> On Fri, Mar 14, 2008 at 9:30 AM, Tobias Koller (GERMO GmbH)
> <[hidden email]> wrote:
>> I have a problem when I set my tableModel and columnModels at runtime.
>
> Unfortunately, changing the column model is not supported.  If you
> look at the documentation for the tableColumnModel property, it
> specifies that.  I once looked into making that run-time configurable,
> but there are just so many interactions that was would be really,
> really difficult to do.  One of those interactions pertains to the
> cell renderers which, as you're finding, don't get re-bound as one
> would expect.
>
> Derrell
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
View this message in context: http://www.nabble.com/problems-when-setting-tableModel-at-runtime-tp16051523p18540148.html
Sent from the qooxdoo-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: problems when setting tableModel at runtime

Hugh Gibson-2
> I was thinking about setting cellrenderer at runtime just after my
> remote table is rendered.
>
> I need to compare the cell value with the previous row's cell
> value. If there is a difference, I need to high light both of them
> in red color. This should happen for all visible rows in the Remote
> Table
>
> Can somebody give me some hints on how to do that?. I have some 15
> columns.

The difficulty is accessing the previous row's information.

I've got a custom cell renderer (and row renderer) and it has a cellInfo
parameter being a map of the cell information. I can access the row
information using cellInfo.rowData.

In the row data there is a map from column name to column value which is
accessed using knowledge from the column definition passed through to the
table constructor. There's nothing stopping you putting more information
in the row data using another key. Therefore when a row or cell renderer
is called I can access that information and do special formatting.

In your case the server needs to add information for each row, about
whether the cells are equal or not, maybe in a bool array. That data can
be retained in the row map and accessed by the cell renderers to set the
data correctly.

You could calculate the equality in the remote table model but you will
have to access the previous row's data which won't be possible if you
have just accessed a block in the middle of the table (e.g. the user has
scrolled there using the thumb). You don't have the previous row's
information. It's only the server that can do the calculation for you.

Hugh

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: problems when setting tableModel at runtime

kanugula

Hugh, thanks for your suggestion.

I was successfull in implementing cellrenderer. The following code works
great. No performance issues.
CustomCellRenderer.js
_getCellStyle : function(cellInfo)
    {
          var tableModel = cellInfo.table.getTableModel();
          var currRow_CellValue = tableModel.getValue(cellInfo.col, cellInfo.row);
                       
          var siblingRow_CellValue;
          if (cellInfo.row % 2 == 0)
         {
             siblingRow_CellValue = tableModel.getValue(cellInfo.col,
cellInfo.row+1);
         }
         else
         {
             siblingRow_CellValue = tableModel.getValue(cellInfo.col,
cellInfo.row-1);
         }
                       
        if (currRow_CellValue != siblingRow_CellValue) {
          return "color:FF0000";
            }
        else
        {
            return arguments.callee.base.apply(this, arguments);
        }
}

I am also developing a custom row renderer to set even/odd colors for set of
two rows instead of default one row. It is breaking when I do thumb scroll.
This may be what your are saying  about accessing about previous row's data.

CustomRowRenderer.js
// overriden
  createRowStyle : function(rowInfo)
  {
     var rowStyle = [];
     rowStyle.push(";");
     rowStyle.push(this._fontStyleString);
     rowStyle.push("background-color:");

     if (rowInfo.focusedRow && this.getHighlightFocusRow())
     {
         rowStyle.push(rowInfo.selected ? this._colors.bgcolFocusedSelected
: this._colors.bgcolFocused);
     }
     else
     {
         if (rowInfo.selected)
        {
        rowStyle.push(this._colors.bgcolSelected);
        }
        else
        {
        if (rowInfo.row % 2 == 0) {
            if (this._lastColor == this._colors.bgcolEven)
           {
               rowStyle.push(this._colors.bgcolOdd);
               this._lastColor = this._colors.bgcolOdd;
           }
           else
           if (this._lastColor == this._colors.bgcolOdd)
           {
               rowStyle.push(this._colors.bgcolEven);
               this._lastColor = this._colors.bgcolEven;
           }
           else
          {
              rowStyle.push(this._colors.bgcolEven);
              this._lastColor = this._colors.bgcolEven;
          }
        }
        else
        {
             rowStyle.push(this._lastColor);
        }
        }
      }

      rowStyle.push(';color:');
      rowStyle.push(rowInfo.selected ? this._colors.colSelected :
this._colors.colNormal);

      return rowStyle.join("");
  }

  this._lastColor is my state variable to track the last row color. How do I
reset it when the user scrolls the data? Also, I need to add the code for
updateDataRowElement().

I am tryingto accomplish this at the client side, if possible. May be I
should do some trick at the server side to add the color for each row.

Thanks.
Kanugula.




Hugh Gibson wrote:

>
>> I was thinking about setting cellrenderer at runtime just after my
>> remote table is rendered.
>>
>> I need to compare the cell value with the previous row's cell
>> value. If there is a difference, I need to high light both of them
>> in red color. This should happen for all visible rows in the Remote
>> Table
>>
>> Can somebody give me some hints on how to do that?. I have some 15
>> columns.
>
> The difficulty is accessing the previous row's information.
>
> I've got a custom cell renderer (and row renderer) and it has a cellInfo
> parameter being a map of the cell information. I can access the row
> information using cellInfo.rowData.
>
> In the row data there is a map from column name to column value which is
> accessed using knowledge from the column definition passed through to the
> table constructor. There's nothing stopping you putting more information
> in the row data using another key. Therefore when a row or cell renderer
> is called I can access that information and do special formatting.
>
> In your case the server needs to add information for each row, about
> whether the cells are equal or not, maybe in a bool array. That data can
> be retained in the row map and accessed by the cell renderers to set the
> data correctly.
>
> You could calculate the equality in the remote table model but you will
> have to access the previous row's data which won't be possible if you
> have just accessed a block in the middle of the table (e.g. the user has
> scrolled there using the thumb). You don't have the previous row's
> information. It's only the server that can do the calculation for you.
>
> Hugh
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
View this message in context: http://www.nabble.com/problems-when-setting-tableModel-at-runtime-tp16051523p18597519.html
Sent from the qooxdoo-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: problems when setting tableModel at runtime

Hugh Gibson-2
> if (rowInfo.row % 2 == 0) {
>    if (this._lastColor == this._colors.bgcolEven)
>   {
>       rowStyle.push(this._colors.bgcolOdd);
>       this._lastColor = this._colors.bgcolOdd;
>   }
>   else
>   if (this._lastColor == this._colors.bgcolOdd)
>   {
>       rowStyle.push(this._colors.bgcolEven);
>       this._lastColor = this._colors.bgcolEven;
>   }
>   else
>  {
>      rowStyle.push(this._colors.bgcolEven);
>      this._lastColor = this._colors.bgcolEven;
>  }

That's the problem for the row colour. You can jump around in the table
and the last colour will be wrong.

Do it like this:

if ((rowInfo.row >> 1) % 2 == 0)
{
  rowStyle.push(this._colors.bgcolEven);
}
else
{
  rowStyle.push(this._colors.bgcolOdd);
}

">>" is the shift operator - it does an integer division by 2.

So you get:

Row    >> 1     % 2   colour
0       0        0     Even
1       0        0     Even
2       1        1     Odd
3       1        1     Odd
4       2        0     Even
5       2        0     Even

etc.
   
Hugh

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel