I want to add a button to the HeaderSpan of ListGrid in SmartGWT. I tried using the 'HeaderSpan.setAttribute((String property, Object value)) method but it did not work. Below is the example I tried with:-
ListGrid countryGrid = new ListGrid();
HeaderSpan ident = new HeaderSpan("Identification", new String[]{"countryCode", "countryName"});
ident.setAttribute("control", new Button("Test"));
countryGrid.setHeaderSpans(ident);
countryGrid.draw();
Please help!
Here's doing it without JSNI or DOM: This grid updates contents of the second span header with dynamic content when datasource is loaded. Alternately, you could use "onDraw" instead of "dataArrived", if the contents are static
Using headerSpans.getParentElement().getChildren()) also works if you are on version of smartgwt preceding 4.1d
Finally I found the way to add button to a HeaderSpan. Below is the code (Have omitted import statements for brevity):-
The client class will call the AdvancedListGrid.setHeaderSpanButtons() method to add buttons to the header span. Of course you can customize the method to meet your needs.
I'm testing it, as I need to put a Calendar in a HeaderSpan. Thanks for sharing your idea, it's of great help, although it took a while to set the correct imports.
A note : the setHeaderSpanButtons() method will only work if the datasource of the ListGrid is set. If it's not, no header at all is shown.
An improvement : you can add a break in the loop, no need to loop the whole NodeList:
A question : what is the purpose of this line:
And finally, it doesn't work for me - the span stays always as text "Identification". Any suggestions?
Thanks.
Did you test it on IE? I tested in FF and it works fine, but I have problems when clicking around my app in IE. As far as I read, it is due to the mix of GWT and SmartGWT. So I guess it's better to use a ToolStrip like in this example: http://www.smartclient.com/smartgwt/showcase/#grid_appearance_preferences