:: Forum >>

2.5.x populate w/2-dimensional array

Hello
Does the new API make it possible to directly populate with a dynamic array? I have and it only "gets" the first row. I know this is an obtuse question, I just cant ferret out the answer. tia.
cpanon
Thursday, May 6, 2010
Hi
To provide more data. I am using this call
obj.setCellData(function(i,j){return lines[i][j]});
What is odd is there is data there, I can infer from grid width, but it does not display whether one line or many. Further when I add obj.refresh() it oddly changed the know width and eliminated the scroll bars. I am also using the row coloring technique that works very well.

I also tried
obj.setDataTextfunction(i,j){return lines[i][j]});
and that eliminated the scroll bars and truncated the know width, also without showing the data.

When I use the obj.setCellData(lines), it displays only the first row of data. I will keep pushing/pulling levers and looking for my food pellet, grin.
cpanon
Friday, May 7, 2010
Look at the sample code in \examples\grid behavior - scrolling\virtual.htm
Alex (ActiveWidgets)
Friday, May 7, 2010
Hi Alex
Thank you.
From the example, not seeing the reference to the array I tried this
obj.setCellText(function(col,row){return lines[row][col]});
obj.refresh();
The following results occurred:
1. It still only showed the last row of a two row array.
2. Lost the alternating colors that are established on default as below even after the refresh.
obj.refresh();
function alternating(){
return this.getRowProperty("position") % 2==0 ? "even" : "odd";
}
obj.getRowTemplate().setClass("alternate", alternating);

So I am still pushing these new levers, still searching for that oh so savory food pellet, grin. Okay I will stop the analogy after this, grin2
cpanon
Friday, May 7, 2010
Hi Alex
Can you instruct me on how to syntactically do what is obvious that I want to do? I dont want to sound opportunistic or flippantly quid pro quo, however the functional answer to this will facilitate my demo that will fund the purchase of your product. It would also contribute to better understanding your technology which even in the "shadows" is enticing.
cpanon
Monday, May 10, 2010
Sorry, what you are trying to do it is not obvious to me. Why don't you just start with a working sample code and modify it step by step until you get what you need?
Alex (ActiveWidgets)
Monday, May 10, 2010
Hi Alex
Sorry, I wasnt trying to be sarcastic, just obtuse. Please let me try again, it may be helpful to others, if only as an example of how not to think.

I am building a two dimensional array in memory. I want to somehow "give" that array to activewidgets to display. I understand how setCellText is quite sophisticated and Java-like and can take an anonymous function. I thought the naive substitution of my 2-d array, lines, with the assumed syntax would be proper to have activewidgets grid display all the cols and rows, as in the example without an array object. Also I had the alternate shading of row background working and when I tried the syntax above it "broke" that is, just white.

I understand this is too much attention. I am willing to purchase the product a priori and continue this privately under full customer support; it must be able to do this somehow. tia.
cpanon
Monday, May 10, 2010
If you mean you're building the array dynamically, then have a look at this:

http://www.users.on.net/~asm/calendar/

I build the grid data for each calendar month dynamically. The code may be a little hard to follow but I suspect its more or less what you're looking for.
Anthony
Monday, May 10, 2010
Hi Anthony
Thank you. There is quite a bit of clever coding there. I am really just simple minded. What I was looking for is a way to iterate through my lines[rows][cols] and "feed" aw.grid setCellData or setCellText, I just dont see how to set that up. I could iterate through my lines array, but that is what I thought my syntax did:
obj.setCellText(function(cols,row){return lines[row][cols]}) Can my lines be seen in the anonymous function? How can aw.grid "know" to safely iterate the values for cols and row?
cpanon
Monday, May 10, 2010
The crux of what you probably want to look at is the MakeCal() function. In it, setCellData() is called.

But what you need to understand is that AW calls it for each row and column. That's why there appears to be no iteration. The situation may be different for you if you have an array of some certain size and a grid that only displays a number of rows at a time. In my case, the grid is of fixed size and I populate each cell.

You should be able to access any global variable you set within any function you write. However, iteration is probably a better option for you.

Perhaps you can explain how this data comes to be? If the array already exists, why not assign it using the regular methods?
Anthony
Tuesday, May 11, 2010
Hi Anthony
The array does indeed already exist. It is exactly those method calls that I do not presently know, other than the setCellData(). Is there some method call that can take the entire pre-existing dynamically built array without any iteration?
cpanon
Tuesday, May 11, 2010
Are you trying to do something like this -

var array = [
    ['cell 1.1', 'cell 1.2'],
    ['cell 2.1', 'cell 2.2'],
    ['cell 3.1', 'cell 3.2']
];

var obj = new AW.UI.Grid;
obj.setCellText(function(col, row){return array[row][col]});
obj.setColumnCount(2);
obj.setRowCount(3);

document.write(obj);
Alex (ActiveWidgets)
Tuesday, May 11, 2010
I think he just wants to assign an array like this -

http://www.activewidgets.com/grid.howto.data/javascript-array.html
Anthony
Tuesday, May 11, 2010
Hi All
Thank you for the attention. I have had a serious hardware failure and been unable to try the approaches. I believe I already tried giving the call the array, the only difference is the array is dynamically generated each time I need to display the grid. That should not make any difference. I will try the suggestions and report back when possible
cpanon
Wednesday, May 12, 2010
Hi All
It still does not work. I am doing this
for(i=0;i<dbData.length;i++){
lines[i]=new Array();
for(j=0;<dbData.headers.length;j++){
lines[i][j] = dbData.headers[i]; //from a JSON object
}
}
...
obj.setCellData(lines);

I know I have a n-row array in lines and I am only getting the last displayed. This happens with other multi-row data. The data is perfect in the array, lines, but it is not a static struct. Is there a syntax where I can, myself dynamically iterate the array and "feed" each cell value index to aw.grid? Or is there some other way? Sorry for taking up so much bandwidth on my little problem, but it may be pedantic for others and the product's greater use.
cpanon
Wednesday, May 12, 2010
Are you also using this?
Missing that could cause the 'single-line' issue.
obj.setColumnCount(lines[0].length);
obj.setRowCount(lines.length);
Wednesday, May 12, 2010

This topic is archived.


Back to support forum

Forum search