Correct way to update table model in Extended Grid
Hello,
I have scanned through the forum, and tried every combination of suggestions I have found without success.
All I want to do is update a parameter on a previously defined table model, which is attached to a grid, and .request() again and have it refresh the grid. From everything I see and read, this is what should be happening.
The grid loads the data from the model initially just fine. The model is returning filtered data. In Firefox nothing happens. In IE, it appears that the model has refreshed because I can get scrollbars to appear when I know the filtered data exceeds the scroll window. I have tried various combinations of clearCellModel()+setCellModel(), refresh(), etc., with mixed results (enough to know the model is refreshing correctly).
The point is that refreshing the model should handle everything automatically (at least in my mind). Simple example below. Any assistance appreciated as always.
myTable = previously setup and working model...
myTable.request();
myGrid.setCellModel(myTable);
myCombo.onItemClicked = function(event, index){
var client_id = this.getItemValue(index);
myTable.setParameter("where", "client_id='"+client_id+"'");
myTable.request();
}
Curt K.
April 21,
Hi Curt,
If I remember correctly, when a filter is applyed , some other models are involved .
Search for clearRowModel / clearScrollModel / sortModel and rowcount is playing too, I'll try to find one or two posts related flashing me now.
Carlos
April 21,
I've attempted a few examples of those, however none have achieved the desired result of simply refreshing the grid with new data......:o(
Am I being demanding in expecting that a re "request()" in the model should handle everything in the grid by default? If I was writing a windows app (which is my history, sorry) in C#, or whatever, this would be a non-issue. I understand that unfortunately when dealing with different browsers, versions, etc., there can be strange issues.
Curt K.
April 21,
OK, so I can see that if I fudge a delayed refresh on the grid it starts to do it's thing. Now I have two problems: In IE the combo doesn't hold the selected value, and in FF the combo just stays dropped down and nothing happens.....
So the first question is, what might the correct event be to attach a grid refresh to, and what needs to be done to tell the combo to complete it's event ?
myTable = previously setup and working model...
myTable.request();
myGrid.setCellModel(myTable);
myCombo.onItemClicked = function(event, index){
var client_id = this.getItemValue(index);
myTable.setParameter("where", "client_id='"+client_id+"'");
myTable.request();
setTimeout(myGrid.refresh(),5000);
}
Curt K.
April 21,
Anyway this is a known issue, better search by 'onItemClicked' or 'popoup' I will try to find it also (tomorrow).
Are you making a VS C# win32 exe with dll's?
I am also trying a different approach to a portable standalone/ajax executable that woul be also used to search an AW fixing-posts database (I get lost finding my own threads)
:-))
Carlos
April 21,
OK, I see that using the "onItemSelectedChanged" event is the better choice for this. It doesn't interfere with the combo functionality, and the selection of the item completes.
So now I can get the example to work in IE, although I know the refresh() is not the right place and/or should not be required. In FF there is no refreshing at all.
myCombo.onItemSelectedChanged = function(value, index){
var client_id = this.getItemValue(index);
myTable.setParameter("where", "client_id='"+client_id+"'");
myTable.request();
myGrid.refresh();
}
Curt K.
April 21,
Try myGrid.getRowsTemplate().refresh() or myGrid.getScrollTemplate().refresh() sometimes is enought and shorter than a full myGrid.refresh() , just to avoid duplicate refreshing the 'data' part (or clear the Models affected).
Carlos
April 22,
Carlos,
I found one of your previous posts where you suggested something along the lines:
m_table.response = function(xml) {
m_grid.clearRowModel();
m_grid.clearSortModel();
m_grid.clearScrollModel();
m_table.setXML(xml);
m_grid.setRowCount(m_table.getCount());
m_grid.refresh();
}
This makes more sense to me from an event-driven view. It seems to have the same results in IE, which means it works, however in Firefox it still does not refresh the grid. :o(
Curt K.
April 22,
Carlos, thanks for all your assistance. I still cannot find any resolution.
Why does this have to be difficult. It's a simple task.
Curt K.
April 22,
FYI, the code in table.js handles all the stuff that has been basically referenced above, which I would expect :
obj.response = function(xml){
this.setXML(xml);
if (this.$owner) {
this.$owner.clearScrollModel();
this.$owner.clearSelectedModel();
this.$owner.clearSortModel();
this.$owner.clearRowModel();
this.$owner.setRowCount(this.getCount());
this.$owner.refresh();
}
};
Curt K.
April 22,
I've added an alert just after "this.$owner.refresh();", and it is alerting correctly in IE and Firefox after the table has been re-requested. However as described above, the grid is not refreshing in Firefox. If this is a bug, perhaps there is a good workaround? Thanks in advance.
Curt K.
April 23,
I think I dicovered something interesting.
Somehow (need to check it a few more) the combo is iterfering.
Try to reproduce it using a Button.. i.e
var Abutton = new AW.UI.Button;
document.write(Abutton);
Abutton.onControlClicked = function(event){
var client_id = '';
myTable.setParameter("where", "client_id='"+client_id+"'");
myTable.request();
myGrid.refresh();
}
In a simple sample I created (using a call to my filter function) the combo returns an empty grid while the button do it as expected)
Not sure if it's the closepopup, te focus on the combo-input or something else ( I also tried with onControlTextChanged with no luck)
HTH
Carlos
April 23,
Uppss!
Sorry I tried again
myCombo.onControlTextChanged = function(text){
....
and works!
so should be onItemSelectedChanged that is firing twice ( one per each action i.e deselected and then selected new)?
myCombo.onItemSelectedChanged = function(event, index){
alert(index)
Please try it..
Carlos
April 23,
OK Carlos, I tried as you suggest with no luck. Without myGrid.refresh(), the grid won't refresh at all in IE, but either way
no refresh in FF. I don't understand why refresh() is even needed to get it to work as it's part of the response function of Table.
myCombo.onControlTextChanged = function(text) {
var client_id = this.getItemValue(this.getSelectedItems());
myTable.setParameter("where", "client_id='"+client_id+"'");
myTable.request();
myGrid.refresh();
}
Are you out there Alex?
Curt K.
April 24,
It would help a lot if you can post your adds to the custom AW.XML.Table ,just to get a confirmation from Alex or anyone XML expert ( I'm not one) ;-) that your "where" Parameter wouldn't create conflicts with FF ( There are at least three "if !AW.ie" in the original) - Otherwise they are going to feel "a bit blind" in this case.
Anyway I would only suggest changing "setParameter" with "setProperty" by defineProperty("any"); this way you can call table.setAny("newvalue") or table.getAny() where needed.
( that works fine for me in CSV data model ).
HTH
Carlos
April 28,