3.2.0

Things are not clear at all...

I'm trying to use the grid with C# and can'y understand manyhtings :

1-What is the difference between AW.XML.Grid and Active.Control.Grid ?

2-if Active.XML.Table is the data source, does it means i can change one of its cells and the grid will reflect the change ?
What i'm trying to achieve is by XMLHttp update some cells of the grid.

What should i do ? Create a Table then load some Data, every 20 sec query the server and get some updates. Then how can i find the lign to update in the model then force the cell to refresh ?

Any help appreciated
John
November 29,
After http request (get new myData from server) then do (JS) :

obj.setRowCount(myData.length);
obj.setCellText(myData);
obj.refresh();

This is a complete refresh of the whole grid, cause you might not know what has been changed since last server request...
Otherwise, there are some cell refresh functions ... see posts on this forum

Can't really help further, but the solution you are asking for is working OK, no problem...
Paul
November 29,
Thanks Paul

Bu what about telling the grid to change the color of the change Data ?
John
November 29,
If you mean by this that you want to change the color of one particular row, then it is not directly linked to the myData array, but to the css styles, so I'do sthg like :
#myGrid .aw-row-1 {color: red}

In this example, this is ok for line 1 only.

Then you can repeat this line for all occurences of lines that need to be enlightend!

Check ActiveWidgets\examples\quickref\grid.htm for further info.

Paul
November 29,
Paul

thanks for your answers.

However, let me precise what i meant exactly.

My understanding of the grid is that there is a model and a separate grid "bound" to it.

After the first binding, some data has changed and i need to refresh the model and/or the grid.

Rebinding the whole grid is not a good idea as only a few cells need to be updated.

So my Question:
*how can i access a partular cell (by id would be great)and where (in the model or in the grid) ?
Julien
November 29,
Well, according to me, you can either change
myData[i][j] = "Text"

, apply style :
#myGrid .aw-row-2 .aw-column-1 {color: red; font-style: italic}

and then call to refresh
Or you can directly modify the value of the cell content by doing
obj.setCellText("text", 2, 3);	// single cell at column 2, row 3


You can also refresh a column :
obj.getCellTemplate(2).refresh();

And therefore, I am pretty sure that you will find a method to maybe only refresh one cell...

To my knowledge, you can access a particular cell (not by id, but by rowNum and colNum) in either the model or the grid. I don't know which is preferable, but I think that if you modify the grid, then you might not need to refresh the whole grid, which is a bottleneck here.

But on the xml and http-request infos, I won't be able to help you

Hope this helps
Paul
November 29,
For sure it helps !

A final question how do you apply style ?

Thanks many times

John
Julien
November 29,
Ok Julien or John,

I know it might not be very easy to dig into the reference, but either you have skills at developping and you should find all you need for basics questions like those in the examples, or the API will just be to hard for you. According to me, you shall be able to do it, so take more time to see what is released in details, and you will find (as I do) all your answers in the examples...

Anyway, once again, your solution is detailed in examples : check ActiveWidgets\examples\quickref\grid.htm, you will find the following lines :

/********************************************************************
    modify cell template
********************************************************************/

//	obj.getCellTemplate().setStyle("color", "red");			// all columns
//	obj.getCellTemplate(1).setStyle("color", "green");		// column-1
//	obj.getCellTemplate(2, 3).setStyle("color", "blue");	// column-2, row-3


Otherwise, declare styles in css <style> tags like I already said earlier in this post...

Hope you get it right as I now do, and feel confortable with this wanderfull tool
Paul
November 29,
Paul

Ok i think i begin to understand. One reason it is difficult is that the doc is really unclear.

I can modify some data and update the grid but when i apply
obj.getCellTemplate(2, 3).setStyle("color", "blue")

there is no effect. Here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="runtime/lib/aw.js"></script>

<!-- grid format -->
<style>
.aw-grid-control {height: 100%; width: 100%; margin: 0px; border: none; font: menu;}
.aw-row-selector {text-align: center}

.aw-column-0 {width: 80px;}
.aw-column-1 {width: 200px;}
.aw-column-2 {text-align: right;}
.aw-column-3 {text-align: right;}
.aw-column-4 {text-align: center;}

.aw-grid-cell {border-right: 1px solid threedlightshadow;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
#myGrid .aw-alternate-even {background: #fff;}
#myGrid .aw-alternate-odd {background: #eee;}

</style>
</head>
<body>
<script>

function change()
{
myData["111"][1]="Test";
myData["222"][2]="Test";
//No refresh
}

var myData = [];

myData["111"] = ["MSFT","Microsoft Corporation", "314,571.156", "32,187.000"];
myData["222"] = ["ORCL", "Oracle Corporation", "62,615.266", "9,519.000"];
myData["333"] = ["SAP", "SAP AG (ADR)", "40,986.328", "8,296.420"];
myData["444"] = ["CA", "Computer Associates Inter", "15,606.335", "3,164.000"];
myData["555"] = ["ERTS", "Electronic Arts Inc.", "14,490.895", "2,503.727"];

var myColumns = ["Ticker", "Company Name", "Market Cap.", "$ Sales"];

var obj = new AW.UI.Grid;
obj.setId("myGrid"); // necessary for CSS rules
obj.setCellText(myData);
obj.setHeaderText(myColumns);

obj.setRowIndices(["111", "222", "333", "444", "555"]);

obj.setRowCount(5);
obj.setColumnCount(4);

obj.setSelectorVisible(true);
obj.setSelectorWidth(35);
obj.setSelectorText(function(i){return i});
obj.setSelectorText(function(i){return this.getRowPosition(i)+1});

document.write(obj);

alert (myData["111"][0]);

myData["111"][1]="Julien";
myData["222"][2]="Julien";

obj.getRowTemplate("111").getItemTemplate(1).refresh();
obj.getCellTemplate(1, 1).setStyle("color", "red");
obj.getCellTemplate().setStyle("color", "red");
obj.onCellClicked = function(event, col, row){
window.status = "row: " + row + " column: " + col;
};
</script>

<button onclick="change()">Change</button>
<button onclick="addRow()">AddRow</button>
Lenny
November 29,
!!!
Well I added obj.refresh() 4 lines before the end of your script and seems to work to me!

saved a lot of time for you today?
Paul
November 29,
Please use '#' button on left of replies to indicate code, it will be much clearer and easy to understand
Paul
November 29,
Paul

I would like to refresh only the cell not all the grid...

Is that possible ?

Thanks so much !
Lenny
November 29,
Unfortunately lenny, I don't have a perfect knowledge of the system, and my answers were really trivial...
For this one, I never went so far into the grid, but I am sure that many of the users who post in this forum might be able to help...
Try to get into debug, you might get with MSOffice JS debugger a complete list of all methods and members available on the grid : check all functions available on grid, columns, rows and cells that might say refresh(), or maybe even simpler : sthg like obj.refresh(2,3); I didn't test this!
Paul
November 29,
Lenny, you just need to put all changes ordered inside change() function.
Try something like:

function change(){
myData["111"][1]="Julien";
myData["222"][2]="Julien";

obj.getCellTemplate(1, 1).setStyle("color", "red"); 
obj.getCellTemplate().setStyle("color", "red");

obj.getRowTemplate("111").getItemTemplate(1).refresh();
obj.getRowTemplate("222").getItemTemplate(1).refresh();
}
Carlos
November 29,
Carlos

Yes it works but then why do you need to write twice setStyle("color", "red"); :

obj.getCellTemplate(1, 1).setStyle("color", "red");
obj.getCellTemplate().setStyle("color", "red");

I don't understand why the second line ?

Thanks
Lenny
November 30,
You are right, here is a better way (no refresh needed)

function change(){
myData["111"][1]="Julien";
myData["222"][2]="Julien";
obj.getRowTemplate("111").getItemTemplate(1).setStyle("color", "red");
obj.getRowTemplate("222").getItemTemplate(1).setStyle("color", "red");
}
Carlos
November 30,
Carlos

This is strange as the color changes but not the text !
Dan
November 30,
You will need to refresh for the text to take affect.
or you should use the obj.setCellText("text",1,2)
Alex from Sydney
December 21,

This topic is archived.

See also:


Back to support forum