I can refresh a livegrid by doing
livegrid.cancelMenu();
livegrid.ClearSelection();
if (livegrid.bookmark) livegrid.bookmark.innerHTML=" ";
livegrid.clearRows();
livegrid.buffer.fetch(-1);
This will reload the entire grid, and reset the view to start at row 0.
Is there a way to refresh the displayed data without changing the view
to the first row? So that if I'm viewing records 101-110, I will still
be viewing those records after the refresh?
on 26.08.2007 00:43
on 26.08.2007 20:49
I think the problem is that you have to pass an offset value of '-1' to
fetch in order to force a server hit. I modified the fetch function as
follows so I could force a server hit and pass in the correct offset:
In Rico.Buffer.AjaxXMLMethods object in the file ricoLiveGridAjax.js:
fetch: function(offset, fromBuf) {
var fromBuffer= typeof(fromBuf) == 'undefined'?true:fromBuf;
if (this.isInRange(offset) && fromBuffer) {
Rico.writeDebugMsg("AjaxXML fetch: in buffer");
this.liveGrid.refreshContents(offset);
return;
}
this.processingRequest=true
Rico.writeDebugMsg("AjaxXML fetch, offset="+offset);
this.liveGrid.showMsg("Waiting for data...");
this.timeoutHandler = setTimeout( this.handleTimedOut.bind(this),
this.options.bufferTimeout);
this.sendAjaxRequest(offset,0,this.ajaxUpdate.bind(this,offset));
}
There may be a better or more elegant solution, but this works for me.
HTH
on 31.08.2007 13:53
Hi, I didn't test this too much so let me know if it cause you problems. var lastOffset=livegrid.buffer.lastOffset; livegrid.buffer.clear(); livegrid.buffer.fetch(lastOffset); or (same thing) var lastOffset=livegrid.buffer.lastOffset; livegrid.buffer.clear(); livegrid.buffer.lastOffset=lastOffset; livegrid.buffer.refresh(); good hunting
on 31.08.2007 17:19
Robert: I'm actually using AjaxSQL buffers so I wasn't able to test out your code. Alex: That's pretty much what I've been doing. Everything about it works, except the data displayed in the livegrid isn't updated. In other words, the buffer is refreshed and contains new data, but the cells in the livegrid still display the old data. If you scroll down one row after executing your code, the updates are all reflected in the displayed cells. What I've been looking for is a function that syncs the displayed values in the live grid to the values stored in the livegrids buffer. I've been combing through the rico*.js files for a few days now and haven't found it yet. I'm still trying to get a grasp on the general flow of the livegrid functions. If anyone has any tips I'd be happy to investigate. Either way I'll post what I find as soon as I have something.
on 02.09.2007 06:58
Hi Ed, So maybe it's a combined solution. Instead of clearing just the grid, or just the buffer try to clear both before making the ajax request. I don't think you'll find an already implemented function for what you want to accomplish, but for sure you have in the Rico framework the support to do one. good hunting
on 05.09.2007 04:53
I haven't been able to do what I was originally asking about, but I have
come up with a way to sync the displayed values with the values stored
in the buffer. Because I plan on adding more custom functions I've
extended LiveGrid. The file is attached to this post, and copied and
pasted below.
<pre>
Rico.LiveGridExtended = Class.create();
Rico.LiveGridExtended.prototype = {
initialize: function( tableId, buffer, options ) {
var livegrid = new Rico.LiveGrid(tableId, buffer, options);
Object.extend(this, livegrid);
Object.extend(this, new Rico.LiveGridExtendedMethods);
}
};
Rico.LiveGridExtendedMethods = function() {};
Rico.LiveGridExtendedMethods.prototype = {
updateView: function () {
for(var r = 0; r < this.pageSize; r++) {
this.updateRowView(r);
}
},
updateRowView: function (windowRow) {
for(var c = 0; c < this.columns.length; c++) {
var container = $(this.tableId + '_' + windowRow + '_' + c);
container.innerHTML =
this.columns[c].getFormattedValue(windowRow);
}
}
};
</pre>
To update a cells value in the buffer I call something like
<pre>livegrid.buffer.setWindowValue(5, 1, 'value')</pre>, where 5 is the
row index (this is the displayed row index. the first row displayed in
a livegrid is always index 0, and the last row's index is equal to the
livegrid's pageSize-1. setWindowValue will convert the displayed window
row index to the correct buffer row index), 1 is the column index, and
'value' is the new value.
After setting the new value in the buffer, I call
livegrid.updateRowView(5). That will change the displayed values in the
cells in window row index 5 to the values stored in the buffer.
I'm going to attempt to use these functions to create an inline editor.
I was thinking I would do an Ajax.Request to update the data, and the
response would be a special case of an AjaxResponse that only has one
row. Then if the AjaxResponse is not an error I can parse the response
and call livegrid.buffer.setWindowValue for each cell in the row, and
then call updateRowView.
For the first version I'm just going to disable editing the column that
the livegrid is sorted on, as this would require doing a refresh of the
grid and displaying from the rows new offset.
Any criticism or comments are appreciated.
on 05.09.2007 14:17
Ed, I don't know why you took the hard way.
If "Is there a way to refresh the displayed data without changing the
view
to the first row?" was what you were "originally asking about", I tried
to get get that after my last post and for me works very simple; my test
scenario also includes some context purposes for the refresh:
function DoAction(action, key)
{
var lastOffset=livegrid.buffer.lastOffset;
livegrid.buffer.clear();
livegrid.clearRows();
livegrid.buffer.lastOffset=lastOffset;
livegrid.buffer.options.requestParameters.push('actionname='+action);
livegrid.buffer.options.requestParameters.push('actionkey='+key);
livegrid.buffer.refresh();
livegrid.buffer.options.requestParameters.pop('actionname='+action);
livegrid.buffer.options.requestParameters.pop('actionkey='+key);
}
Because you do
livegrid.buffer.clear();
livegrid.clearRows();
they get empty so they get syncronized; the disadvantage is that here
the entire buffer and all grid lines get cleared when could have been
cleared just the data displayed to the user.
Hope this helps.
good hunting
on 05.09.2007 18:55
Alex: I'm having trouble getting your example to work. What are the actionname and actionkey parameters used for? I assumed they were something extra that I shouldn't need. If they are needed then that is where I made my mistake. Otherwise I'm still having the same problem of getting the displayed values to match the values in the buffer. After calling your method, everything *appears* to work. The "Waiting for data..." message is displayed, and after it hides itself I'm still at the same point in the grid I had previously scrolled to. A call to my AjaxDataSource is made, and an AjaxResponse is returned with the new, updated values. Examining the buffer also shows that the buffer is updated with the new values. But the values displayed in the grid are still the old values. So it seems I still need to solve the problem of syncing the displayed values to the values stored in the buffer. If you are not having this problem, would you mind posting the full source of your test case? My tests are being run on IIS using ASP.NET 2.0. I will work on recreating just my test cases without all the dependencies of my project and then post the test project here. I'll convert everything to php also, since I imagine more people would benefit from a php example than an asp example.
on 05.09.2007 20:26
My test php application can be downloaded here: http://www.mediafire.com/?eptzozzdlkx It includes a readme file and I tried to document the code where I thought it might be confusing. If anyone finds any problems or has any suggestions please let me know. Post any questions here - I've been checking this forum pretty regularly.
on 09.10.2007 13:43
Alex I am facing the same situation as Ed, where I need to manually refresh the data being displayed in the Livegrid. I also attempted your test with my own code and got the same result as Ed: the grid appeared to update and the buffer had the new data, but the grid still displayed the old data. Is there no function in LiveGrid to force the grid to reload its data from the buffer? Ed's sample code looks great, but I'd rather avoid changing the source of Rico at the moment. Also Ed, do you know if you are using beta 2 or beta 3? Matt released beta 3 sometime last week, but never updated the comments so the documentation still says its beta 3. Orion
on 09.10.2007 15:32
This function works with example 2 to refresh the grid and maintain
scroll position:
function DoRefresh() {
var lastGridPos=orderGrid.lastRowPos
orderGrid.buffer.clear();
orderGrid.buffer.setTotalRows(0);
orderGrid.buffer.foundRowCount = false;
orderGrid.cancelMenu();
orderGrid.ClearSelection();
orderGrid.setImages();
if (orderGrid.bookmark) orderGrid.bookmark.innerHTML=" ";
orderGrid.clearRows();
orderGrid.buffer.fetch(lastGridPos);
}
Matt
on 09.10.2007 17:02
Thank you Matt that has done the trick
on 10.10.2007 02:46
Glad it worked for you. There will be a similar function built into the next release of Rico 2.0. Matt
on 13.11.2007 22:49
Hi Ed, Sorry, it's been a while since I got the chance to check this list but anyway, glad that somebody figure it out. The trick worked for me since the beginning as I originally posted here and guessing that you are into .NET (me also) maybe you will find interesting my effort to wrap LiveGrid into a ASP.NET server control. Check this out http://www.codeplex.com/SharpPieces . Best, Alex
on 11.12.2008 17:28
Hello. I hope it´s not late too reply this question. After looking at my app for a long time, To refresh a buffer on screen is absolutely simple. The secret is to assosiate an Id to each Cell or row (depending what you need) at the time that the App is painting data on screen. Then, You know the relative position in the table, because it's the same for editing the buffer. CONSIDER FILTERING (THE INDEX IN BUFFER IS NOT THE SAME THAN TABLE'S INDEX) Last step is get The object with getElementById method and write the new value with innerHTML propertie it's some thing like this var vnC=buffer.setValue(TABLEROW,TABLECOL,NEWVALUE); var ff=document.getElementById(ID);// THIS IS CELL'S IDENTIFIER ff.innerHTML=NEWVALUE; ****THE MOST OF TIME TABLEROW = ID, BUT CHANGE IN FILTERING OR SORTING IT'S REALLY SIMPLE BUT WORKS VERY GOOD.


