ListGrid OnCellRender type event?

Hi

I have looked through the reference documentation but cannot see what I am looking for although there may be other ways to accomplish my requirement.

Is there any event that fires when a grid cell is drawn or re-drawn? It may be that this could be handled in a different way eg., when the source record’s “column” property value is accessed. Again, I would like to handle such an event when the initials cells are drawn, after a grid loads more rows when it incrementally renders, or if more columns come into view on a horizontal scroll.

There are many grid cell events available but there doesn’t seem to be anything that fires when the cell is drawn/re-drawn.

If I can handle this event, I would like to get a reference to the underlying row/property and the metrics of the cell that was drawn/re-drawn.

Any ideas would be really appreciated.

Regards

-H

Take a look at Canvas.redraw() - in this case you want to override or observe listGrid.body.redraw(), then use APIs such as getFieldWidths() to determine coordinates.

Hi

I have cobbled the code below together, but nothing seems to happen. Could you cast an eye over it and let me know what I have done wrong. If you can embellish it in any way, it would be appreciated!

Many thanks,

-H

	isc.ListGrid.create({
	    ID: "countryList",
		top:50,
	    width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
	    fields:[
	        {name:"countryCode", title:"Code"},
	        {name:"countryName", title:"Country"},
	        {name:"capital", title:"Capital"}
	    ],
	    data:[
	        {countryCode:"US", countryName:"United States", capital:"Washington, DC"},
	        {countryCode:"CH", countryName:"China", capital:"Beijing"},
	        {countryCode:"JA", countryName:"Japan", capital:"Tokyo"},
	        {countryCode:"IN", countryName:"India", capital:"New Delhi"},
	        {countryCode:"GM", countryName:"Germany", capital:"Berlin"},
	        {countryCode:"UK", countryName:"United Kingdom", capital:"London"},
	        {countryCode:"FR", countryName:"France", capital:"Paris"},
	        {countryCode:"IT", countryName:"Italy", capital:"Rome"},
	        {countryCode:"RS", countryName:"Russia", capital:"Moscow"},
	        {countryCode:"BR", countryName:"Brazil", capital:"Brasilia"},
	        {countryCode:"CA", countryName:"Canada", capital:"Ottawa"},
	        {countryCode:"MX", countryName:"Mexico", capital:"Mexico (Distrito Federal)"},
	        {countryCode:"SP", countryName:"Spain", capital:"Madrid"},
	        {countryCode:"KS", countryName:"South Korea", capital:"Seoul"},
	        {countryCode:"ID", countryName:"Indonesia", capital:"Jakarta"}
	    ]
	})		

	isc.Button.create({
	    ID:"testButton",
		title:"Hello",
		stopIt : function() {
			isc.Say("stopit");
		}
	})

	testButton.observe(countryList.body, "redraw", "observer.stopIt()");

That’s going to JS error because of isc.Say() which should be isc.say(). Be sure to install Firebug to get past basics like this. Other than that, looks correct, and you can test it by resizing columns, which will trigger redraw.

Hi

Sorry about making these basic mistakes. I am relatively new to Javascript and SmartClient and come from the world of “MS Intellisense” (C#). Whilst I have a reasonable understanding of things in theory, this whole environment is somewhat challenging until I get the hang of it in practice.

BTW, I do have Firebug running and it didn’t draw attention to my typo? <shrug>

However, the code does now work when I resize a column and I have learned about “observer” so that is good. Is there anything like this that I can “hook” when the cells initially get their value(s), IOW, the first time the grid is rendered? For example, when I scroll down to see the last few rows, redraw doesn’t fire presumably because these value are effectively being drawn/rendered for the first time, irrespective of whether the data is cached or not.

Also, slightly off topic - are the SC js codefiles available in their original form? I tried to look at the source code in the install folder but, it was compacted and on single lines. I could try to understand what is happening if I was able to check the original formatted source of the framework classes. These files may well be there somewhere but I couldn’t locate them.

Thanks for all your help with this - I appreciate your patience.

Cheers

-H

Hi Henryville,

With “isc.Say()” in place and Firebug enabled, you should see a JS error reported by Firebug after resizing columns.

For something similar to Intellisense, check out the SmartClient plugin for Aptana.

You could hook “draw” for the initial render, and “scrolled” for scrolling (both on the body).

In the SmartClient LGPL package, the source is present under the smartclientSDK/source directory. But, you’re not really doing something of the kind of depth where it would make sense to try to familiarize yourself with a codebase of biblical proportions :slight_smile: Just be sure to review the entire Canvas API to understand more of the low-level features that are available.

Hi

I will put the code back to “Say” and check again. Maybe I just didn’t notice the error.

I am already using the SmartClient plugin for Aptana - it certainly helps.

I will certainly review Canvas as per your suggestions.

Thanks again :slight_smile:

Cheers

-H

Hi

I was able to successfully observe “redraw” and “scrolled”. However, absolutely no joy observing “draw”. After thinking about it, it seemed that I may have been observing the method too late so, I set “autoDraw:false” in the grid, called observe and then, listGrid.show(). Unfortunately, this made no difference and observing “draw” for some reason, didn’t seem to work. I changed my observe target to:-

testButton.observe(countryList, "draw", "observer.stopIt()");

and the observe worked! :slight_smile: So, “redraw” and “scrolled” work against countryList.body, whereas “draw” only worked against countryList. I’m not sure why this is - I looked at “body” in the reference docs but I couldn’t see what “members” were available. I looked at the return type for “body” but that didn’t give any clues as to why I could reference some things via body (scrolled, redraw), but not others (draw). Is there a recommendation as to how to discover this kind of information?

Next, I decided to override the “draw” method but came across a curiosity that I cannot explain. See the code below:-

	isc.ListGrid.create({
	    ID: "countryList",
		top:50,
	    width:500, height:224, alternateRecordStyles:true, showAllRecords:true, autoDraw:false,
	    fields:[
	        {name:"countryCode", title:"Code"},
	        {name:"countryName", title:"Country"},
	        {name:"capital", title:"Capital"}
	    ],
	    data:[
	        {countryCode:"US", countryName:"United States", capital:"Washington, DC"},
	        {countryCode:"CH", countryName:"China", capital:"Beijing"},
	        {countryCode:"JA", countryName:"Japan", capital:"Tokyo"},
	        {countryCode:"IN", countryName:"India", capital:"New Delhi"},
	        {countryCode:"GM", countryName:"Germany", capital:"Berlin"},
	        {countryCode:"UK", countryName:"United Kingdom", capital:"London"},
	        {countryCode:"FR", countryName:"France", capital:"Paris"},
	        {countryCode:"IT", countryName:"Italy", capital:"Rome"},
	        {countryCode:"RS", countryName:"Russia", capital:"Moscow"},
	        {countryCode:"BR", countryName:"Brazil", capital:"Brasilia"},
	        {countryCode:"CA", countryName:"Canada", capital:"Ottawa"},
	        {countryCode:"MX", countryName:"Mexico", capital:"Mexico (Distrito Federal)"},
	        {countryCode:"SP", countryName:"Spain", capital:"Madrid"},
	        {countryCode:"KS", countryName:"South Korea", capital:"Seoul"},
	        {countryCode:"ID", countryName:"Indonesia", capital:"Jakarta"}
	    ],
		draw: function() {
			isc.say("draw");
			//this.Super('draw', arguments);
			
		}
	})		

	isc.Button.create({
	    ID:"testButton",
		title:"Hello",
		stopIt : function() {
			isc.say("stopit");
		}
	})

	countryList.show();

If you look at my simple draw override, I am putting up a “say” dialog and not calling Super(). Running the above code, the “say” dialog in “draw” is fired and the grid isn’t drawn. However, if you uncomment the call to Super(), the “say” dialog is fired but the grid is drawn before you click “OK” in the “say” dialog? I have looked at the reference for the “say” dialog and it clearly specifies that it is modal but, the behaviour displayed when you uncomment the call the Super() suggests that “say” doesn’t actually block. If you can clarify what may be happening here, I would really appreciate it.

Finally, due to my unfamiliarity with JS, I was obviously able to override “draw” as per the above code. However, if you wanted to override something like “body.scrolled”, I am not sure how you would specify this in code? For example, the following code demonstrates the question but I know the implementation is incorrect:-

		body.scrolled: function() {
			this.Super('scrolled', arguments);			
		}

What does the JS look like to override a function that is hanging off another member like, in the above case, “body”?

Phew! Sorry about the length of this post.

BTW, as each bit sinks in, I am really starting to like this stuff :slight_smile:

Cheers

-H

“draw” observation will work for any Canvas, but it’s question of timing. autoDraw:true means draw at create(), so there would be no way to observe draw in that case, for the body or for the listGrid as a whole. However with autoDraw:false, show() triggers draw(), hence your approach worked.

Be sure also then when you override a method, you fulfill it’s signature. draw() returns the Canvas itself, so you should “return this;”. More generally, return whatever Super() returns unless you intended to override the return value.

isc.say() is unlike alert() in that it does not block execution. You’ll notice the other Dialog helper methods like isc.askForValue(), provide a callback parameter so you can have a function invoked when the user has answered the dialog.

For overrides of subcomponents, see the AutoChild topic.

Hi

Brilliant - thanks for the advice and confirmation of my observation(s) :slight_smile:

BTW, I had no idea of the concept of AutoChild/sub-components - I will now “swat up” this topic :slight_smile:

It’s really appreciated!

Regards

-H