9 Replies Latest reply on Sep 4, 2008 3:32 AM by jbuechel

    Rerender one particular row in a datatable

    baz

      How can i rerender one row in a datatable?
      A complete example would be nice.
      I haven't found any information about this on the net.
      Wether the richfaces userguide nor the faq(esp. 1.64) answer my question. On the richfaces demosite there is no example for this.
      If i am wrong, please point me to the corresponding docs. Thanks.

      What i want to do?
      I do have several datatables where the user should be able to edit a selected row in a modalPanel.
      My app works. But it is to slow. The user shows the table select a row and edit the data in the modal panel. When the user want to save the work(close the modal panel) the user has to wait several 10 seconds (30-80seconds dependent on the size of the datatable)

      What i do here is to rerender the whole table. But the better solution would be only rerender the edited row.

        • 1. Re: Rerender one particular row in a datatable

          To reRender one row or more rows in a table you need to bind the ajaxKeys attribute of the rich:datatable or a4j:repeat tag if that is how your table is being built.

          This attribute can be a Set of Integers that is the rows to update in the table.

          So to update row five of the table you could have a bean called "tableModel" and a member variable Set rowsToUpdate and you would add 5 to the set and then reRender the table or just the cells in that row. To reRender just a couple cells in the table you would point the reRender tag at the element id in that cell.

          If you need a example let me know and I can post one.

          • 2. Re: Rerender one particular row in a datatable
            baz

            Hello,
            many thanks for your answer.

            bind the ajaxKeys attribute of the rich:datatable

            So i have to set this attribute for rich:datatable. So ar so good.
            But what is ajaxKeys?
            This attribute can be a Set of Integers

            You wrote "can be" instead of "is"
            This concept of ajaxKeys is not clear to me. How is one particular ajaxKey bound to the corresponding row in the table?
            Especially when i sort the table.
            If you need a example let me know and I can post one

            It would be very nice when you can provide an example.
            Ciao,
            Carsten

            • 3. Re: Rerender one particular row in a datatable

              ajaxKeys are the rows you want updated in the datatable. It can be a collection, in most case you could just use a Set.

              So if you want to update rows 2 and 15 in your dataTable, then prior to reRendering you would put 2 and 5 into you set and then these will be the only rows updated in your table.

              • 4. Re: Rerender one particular row in a datatable
                jbuechel

                Hi, I'm fighting with this one too..

                I've got it working with rerendering column by column within a particular row.

                This is the relevant xhtml code:

                <rich:dataTable id="tableId" value="#{dataModel}" var="rowObject" ajaxKeys="#{dataModelManager.ajaxKeys}">
                ...
                <a4j:support event="onRowClick" action="#{dataModelManager.select}" reRender="selected" />
                ...
                <rich:column id="selected" styleClass="fwc-selectedrow-#{rowObject eq dataModelSelection}">
                 <h:outputText value="#{rowObject.name}" />
                </rich:column>
                ...
                


                But:
                Due to reusability i don't like to rerender each column in a certain row but rerender all the columns (td's) within that row at once.

                As you said:
                ...and you would add 5 to the set and then reRender the table or just the cells in that row...

                ..it sould be possible to provide the datatable's id for rerendering. I'm I correct?

                I tried this:
                <rich:dataTable id="tableId" value="#{dataModel}" var="rowObject" ajaxKeys="#{dataModelManager.ajaxKeys}">
                ...
                <a4j:support event="onRowClick" action="#{dataModelManager.select}" reRender="tableId" />
                ...
                


                Unfortunately this rerenders the hole datatable even the ajaxKeys logic stays the same.

                Could you shed some light on that, please?

                Cheers

                • 5. Re: Rerender one particular row in a datatable
                  ilya_shaikovsky

                  tableId in reRender - always meas that whole table will be reRendered.. Are you sure it's good idea to broke this compatibility.?

                  I think you should just point reRender with all cells you need and ajaxKeys with keys.. This isn't so complicated task.

                  • 6. Re: Rerender one particular row in a datatable
                    shadowcreeper

                     

                    "ilya_shaikovsky" wrote:
                    tableId in reRender - always meas that whole table will be reRendered.. Are you sure it's good idea to broke this compatibility.?

                    I think you should just point reRender with all cells you need and ajaxKeys with keys.. This isn't so complicated task.


                    Thanks Ilya, I think I may be finally starting to understand the ajaxKeys attribute (I hope)...

                    I read this to mean that you must include all column ids in the reRender attribute and the columns will check the ajaxKeys EL value to see which rows will have those columns updated... Is this correct?

                    Out of curiosity, are we supposed to be able to update all columns in the ajaxKeys rows? Maybe by saying to reRender the <rich:columns id="allColumns"> element?

                    Thanks.
                    -Shadow

                    • 7. Re: Rerender one particular row in a datatable
                      baz

                      Hello,

                      just point reRender with all cells you need and ajaxKeys with keys.. This isn't so complicated task.

                      What are the keys that i have to put into AjaxKeys?
                      Can you provide a little example? this would be very nice.

                      • 8. Re: Rerender one particular row in a datatable
                        baz

                        [This is the second try of this post. The first one did not make it to the forum:-(]
                        Found it:
                        http://java.dzone.com/articles/an-introduction-to-jboss-richf?page=0%2C5
                        So an ajaxKey is really an index into the table. And the programmer is responsible to provide the right ones.
                        I will try this out and see how well it functions when the table is sortable by users.

                        Is the linked information availablei9n the richfaces doc? I really have found nothing:-(

                        • 9. Re: Rerender one particular row in a datatable
                          jbuechel

                          Thanks ilya_shaikovsky. I'll do that of course if there is no option.

                          This would be nice:


                          Out of curiosity, are we supposed to be able to update all columns in the ajaxKeys rows? Maybe by saying to reRender the <rich:columns id="allColumns"> element?


                          Or what about rerendering columnGroups?
                          <a4j:support event="onRowClick" action="#{dataModelManager.select}" reRender="group" />
                          ....
                          <rich:columnGroup id="group">
                          ...
                          


                          By the way:
                          On earlier documentation I read something like this:
                          <section id="RerenderingPartPage">
                           <?dbhtml filename="RerenderingPartPage.html"?>
                           <title>How to reRender only particular row(s) of dataTable?</title>
                           <para>
                           If you use dataTable then you may use ajaxKeys attribute to bind the rowKeys
                           to be reRendered there. After you need to point reRender on the whole table
                           and only specified rows will be reRedered.
                           </para>
                          </section>
                          


                          That's why I thought it's (or at least, it was) possible.