3.2.0

Philosophy of setCellData vs setCellText

Since I just spent an 2 hours trying to figure out why my 'number format' didn't work and the examples did, (this is second time I've been caught by this). Perhaps it would help if I knew the philosopy (and approiate uses ) of setCell data vs setCellText.

For example, if you populate your array via setCellText, you can then have a numeric only column sort correctly by simply setting the column to NUMBER format. However in order to set a NUMBER format, you must MUST first populate the cells via setCellData. Else Formatting won't work..

So the question is, when is it approiate to use:
obj.setCellData(myData);
vs
obj.setCellText(myData);

What is the downside to always using setCellData?

(and last lastly as an example, why do formating and sorting require differnt methods?)

thanks
-geoff
G. Cayman
February 14,
Well, the logic is that sometimes you want the display text to be different from the actual value, most often with currency and date data types. For this reason the cell model has two separate properties for the text (display text/html) and the value (native type).

Also quite often the transport format (i.e. content of your XML file) is neither of those two. So you need the third property, which is called data in our case and contains the cell value in 'transport' format.

So in the most generic case you should assign cell content using setCellData() method and supply fomatting object which will transform it to html (used for display) and native value (used to sort/filter/etc.).

If you have full control over the 'transport' format - you can send the cell content pre-formatted for display and assign it directly to the text property (usually with javascript array). This method could be much faster because it does not require client-side processing.

And finally if the data is produced on the client-side as native types (i.e. JS Number, Date etc.) it could be assigned to value property and then formatted to text (display) or data (transport) if needed. Though this third approach is not fully tested and may not work in current release.

Alex (ActiveWidgets)
February 14,
Ok so, if I understand correctly all the above...

If one wants the fastest/most efficient method:

set the entire Grid using setCellTEXT

then go back and set the one or two Columns you need to format
by adding the "data structure" values (i.e. obj.setCellData(function(c,r){return myData[r][2]}, 2); ) like this.

That way you only have "DATA" for cols that need it?

So to reiterate, assign cells via setCellTEXT (see CAVEAT below)

then the one col for formatting setCellData. (like this)
obj.setCellData(function(c,r){return myData[r][2]}, 2);
    var number = new AW.Formats.Number;
    number.setTextFormat("$ #,###.###"); 
    obj.setCellFormat(number, 2);


THE CAVEAT being of course USE the function method to populate cells,
ELSE THE col function (setCellDATA(by col) WON't WORK.

ok Do I have it right Alex..
Thanks btw for the philosophy lesson.. (it helps I think ;-)

-geoff



G. Cayman
February 14,
Geoff,

I have a quick question... how often do you need to change the contents of an entire column to a single value? I would think that the caveat of this not working would be an extreme non-issue.
Jim Hunter (www.FriendsOfAW.com)
February 14,
Oh dear, Jim,

I hope I wrote that syntax correctly above...

I _think_ we established back in:
http://www.activewidgets.com/javascript.forum.11782.6/setcelltext-method-used-can-cause.html

That if we didn't use the above method (the CAVEAT above) to populate a Grid, Then later we could NOT use the Column method to setCellDATA..

thus the Caveat...

But YES I agree that this all gets SO complex that one can not use ANY of the examples with OUT A SCORE CARD!

NOW i see that Alex has added one more wrinkle:
IN:
http://www.activewidgets.com/javascript.forum.10412.3/using-data-formats-with-js.html
Here we can SET FORMAT WITHOUT needing to populate with setCellData, apparently UNLIKE seting a NUMBER format..

SO as you can see, there seems to be NO rule to follow! And no way to know who is who, what is what, I think I need better road map here!

-g

G Cayman
February 14,
If it's any help, as an example, I recently loaded a grid with different formats that help me make sense of the "philosophy" talked about above.

I have timestamp data that comes from the server as text strings in the format "08:46 15-Feb-2006", but I want this column to be sortable, so it gets loaded (via js array) with setCellText (it's already in the correct shape for display) and the column has a date format applied (variable i is the column number) to make it sortable:

var date = new AW.Formats.Date; 
date.setTextFormat("hh:mm dd-mmm-yyyy");
obj.setCellFormat(date, i);   // apply format to column i
obj.setCellText(function(i,r){return cells[r][i]}, i);   // load individual column


Also, I have a column of large integer numbers that I want to display with thousands comma separators (e.g. 12,345,678). Because it comes from the server as 12345678 and is not yet ready for display it needs loading with setCellData and a number format applied to put it in the right display format and make it sortable:

var number = new AW.Formats.Number;
number.setTextFormat("#,###."); 
obj.setCellFormat(number, i);  // apply format to column i
obj.setCellData(cells, i);   // load individual column


(there's a story behind this particular number format - see http://www.activewidgets.com/javascript.forum.11471.7/currency-format-not-working.html )

I have a flag specifying the type of each column and I loop through the columns, loading them according to the different approaches above. May not be that efficient, but seems to works for me.

Will


Will
February 15,
Will,
Exactly, I think that is exactly what I was trying to say in this thread
see above on Feb 14. (third post)
That is: Perhaps it's the most efficient to load everything setCellText.
Then then SET setCellData for only those columns that need formating for display?

(Will, thanks for your amplification on your Date formata issue!)

I guess what I was/am asking Alex: Is this the intended/proper/efficient method?

Without a demo or set of defined steps, I think this is a bit hard to follow... I'm trying to think of a cute way to demo all this so one can get it right quickly, see how it all works.. and get on with the application at hand. Ideas???

thanks Will/Alex and all
-g
G. Cayman
February 15,
.. a further comment is to be cautious of loading all columns with setCellText and then using setCellData on individual columns to "fix" their particular formatting retrospectively. I found that once setCellText(cells) had been used on all columns, setCellData seemed not to work on the individual column. When columns have multiple formats, I looped thru each column loading it in the appropriate way, as I mentioned in my previous post.

I acknowledge that I haven't done a rigorous analysis on this, and there may be other factors at play - so this may be valid or not; hopefully Alex can provide some further guidance.

Will
Will
February 15,
Yes Will,
Again see the third post here(the CAVEAT) (and fith). If you READ or populate data via the2darray method.... vs the function method, THEN col the "setCellDATA" method won't work ON COLUMNS!

SEE:
http://www.activewidgets.com/javascript.forum.11782.6/setcelltext-method-used-can-cause.html
for a full discussion of that issue..

So in most cases you can
use
obj.setCellText(function(c,r){return myData[r][c]} );


to get around THAT issue...

I have never understood why that Priority rule exists, or what it accomplishes. But I can tell you that spending many hours here reading and rereading and trying things, THIS IS A MAJOR source of frustration and dissapointment, on things not working when people try even slight modifications on the examples.
G. Cayman
February 15,
Geoff,

I consider this a bug and it will be fixed. I just need to find good way of doing it without much impact on performance - this getProperty method is already quite complex and grid rendering speed is very sensitive to this method performance.

Regarding mixing setCellText and setCellData calls - frankly I never thought of such possibility. In my view if you want to achieve maximum performance you should do all formatting at the server-side and send the data ready for display (and use setCellText() method). However if you don't have control over the data format (for example it comes from shared web service) - then you'd have to use setCellData() and transform it to the required display format at the client side.
Alex (ActiveWidgets)
February 15,
Hmm Hmm it was 'by design' last week ;-)... (its ok, we still love you Alex!!! ;-)

Anyway, more importanly, EVEN if you do have complete control, If you WANT to have numbers SORT correctly, AND you want to, at the very least, put commas and $$$ in properly....

THEN you need have at least that column, set to have a CELLDATA structure.

So as in your example;(if you want to format numbers for display), READ all the data via setCellData, having a cell data structure , for Each cell. Even though you may need it for only one column.

or alternatively
Read entire data in via setCellText, then set the particular column to have a CellData structure also.

So the question is, for large data sets, it is a big performance HIT to have that entire cellData structure when you may only need it for one column...


Alex thanks for the great answers above, I hope that is going to all be in the docs under philosophy why/where/when to use these.

-geoff



G. Cayman
February 15,
Hi Geoff

How can I get the sum of two columns to get the data in third column
Like column3=column1+column2
The all columns have numeric data
Please help in this case.

-vikramaditya Garg
Vikramaditya Garg
May 2,
Hi,

what is the philosophy of setCellValue?

MP
June 26,
Value is used for calculation or comparison (sorting), i.e. in cases where you need actual 'value' and not the 'string'. For example, the data (in XML) might be 2006-06-26T12:00.00+0100, the text 26-Jun-2006 and the value 1151323200000 (numeric date value in js).
Alex (ActiveWidgets)
June 26,

This topic is archived.

See also:


Back to support forum