Grid: set row header caption?

Can we change the row header caption?

For example, we can change the column caption by doing simply,

grid.getColumn("id").setHeaderCaption("X");

See https://vaadin.com/wiki/-/wiki/10674/Configuring+Grid+headers+and+footers

Thanks for the link.

It does not work. Throws following error, if I try replacing row 1, header caption 1.

Why can’t I do simply like this:
grid.getRow(“xxx”).setRowHeaderCaption(“XXX”)

In the attachment, if there are 5 different rows, e.g., 1, 2, 3, 4 and 5… and I want to name Header Rows as A, B, C, D and E… I cannot replace these like I can replace with columns header.

I would be greatful for your efforts, if you can give me an example on how to change this?

//Works for columns

grid.getColumn("xxx").setHeaderCaption("XXX");
// Does not work for headers

grid.getHeaderRow(1).getCell("id").setComponent(new Label("A")); //Throws error like this::

Server Error</pre></p><h3>Caused by:</h3><pre>javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: No row at given index 1
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:352)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:485)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: No row at given index 1
    at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1463)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1420)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:350)
    ... 19 more
Caused by: java.lang.IllegalArgumentException: No row at given index 1
    at com.vaadin.ui.Grid$StaticSection.getRow(Grid.java:2000)
    at com.vaadin.ui.Grid.getHeaderRow(Grid.java:5170)
    at com.bcplatforms.plateEditor.TemplateEditor.initializeGrid48(TemplateEditor.java:318)
    at com.bcplatforms.plateEditor.TemplateEditor.<init>(TemplateEditor.java:101)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at java.lang.Class.newInstance(Class.java:442)
    at com.vaadin.navigator.Navigator$ClassBasedViewProvider.getView(Navigator.java:336)
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:513)
    at com.vaadin.ui.UI.doInit(UI.java:680)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:214)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408)
    ... 20 more
</pre>
<h3>Caused by:</h3><pre>com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: No row at given index 1
    at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1463)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1420)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:350)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:485)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: No row at given index 1
    at com.vaadin.ui.Grid$StaticSection.getRow(Grid.java:2000)
    at com.vaadin.ui.Grid.getHeaderRow(Grid.java:5170)
    at com.bcplatforms.plateEditor.TemplateEditor.initializeGrid48(TemplateEditor.java:318)
    at com.bcplatforms.plateEditor.TemplateEditor.<init>(TemplateEditor.java:101)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at java.lang.Class.newInstance(Class.java:442)
    at com.vaadin.navigator.Navigator$ClassBasedViewProvider.getView(Navigator.java:336)
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:513)
    at com.vaadin.ui.UI.doInit(UI.java:680)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:214)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408)
    ... 20 more
</pre>

When it comes to your exception: probably have to use getHeaderRow(0) as you have only one HeaderRow and the HeaderRow index starts with 0.

Now to what you’re trying to achieve here: I’m guessing from what you were wrote that you have a table/grid sort of like this:

[code]
SomeCol1 | SomeCol2 | SomeCol3


TestData | TestData | TestData
TestData | TestData | TestData
TestData | TestData | TestData
and so on
[/code]and you want something like:

    |   SomeCol1   |   SomeCol2   |  SomeCol3
_____________________________________________
A   |   TestData   |   TestData   |  TestData
B   |   TestData   |   TestData   |  TestData
C   |   TestData   |   TestData   |  TestData
.........

There is nothing like a RowHeader you want right now but you can just add a Column to your grid/table or the container for the A,B,C part in my example and set its “caption” for each row. Set the ColumnHeader-Caption of this column to “” to get the above result and you could also set a CellStyleGenerator to the table/grid to make the “Header”-column look apart from the others.
You should google for adding columns, adding Properties and Cellstyle generators to find out how to implement this.

Hi Marius,

Thanks you for your answer. I really appreciate your help.

Good thing is that I have already done this experiment and got the desired result. Now, my next minor goal is to replace cell contents with buttons. Is it even possible?

Do you have any ideas how to populate Grid cell with buttons? Nothing but all buttons.

Thanks.

When you’re using a Grid try a ButtonRenderer. More information can be found here:
https://vaadin.com/book/-/page/components.grid.html

Thanks a million.