Question

The new row can be added to the associated server-side collection on an action event of a command button or a command link, and the newly added row can be displayed on the client if the whole table is re-rendered.

Is it possible to display the newly added row on the client side without needing to refresh the whole datatable, using the partial rendering, with the help of AjaxKeys or something ?

Thanks in advance for any help :)

Was it helpful?

Solution

You have to rerender whole datatable if you are adding a new row. AjaxKeys may be useful if you want to rerender existing columns.

OTHER TIPS

I am very interested also to know an answer for your question, I can achieve that using traditional Javascript, but when I use rich:datatable I cant add new rows on client.

But I did that using ajax calls to server functions, this function add new empty row to the dataTable List and render the rich:datatable again.

my xhtml page

<rich:column>
<f:facet name="header"><h:outputLabel value="#{msgs.notes}" style="font-size:15px;"/> </f:facet>
<h:inputText    value="#{line.notes}" >
    <a4j:ajax   event="blur" 
    execute="datatable" 
    render="datatable" 
    immediate="true" 
    listener="#{saleBacking.addNewLineInDataTable}"
    oncomplete="document.getElementById('myform:datatable:#{saleBacking.view_no_counter-1}:line').focus();"/>
</h:inputText>
</rich:column>

and in the maneged bean

public void addNewLineInDataTable(AjaxBehaviorEvent event)
    {
        SaleLine saleLine = new SaleLine();
        saleLine.setId(salesLineslist.isEmpty() ? 1 : salesLineslist.get(salesLineslist.size() - 1).getId() + 1);
        salesLineslist.add(saleLine);
        saleLine = new SaleLine();
        saleLine = new SaleLine();
        saleLine.setSaleId(sale);
        saleLine.setViewNo(++view_no_counter);
        saleLine.setDiscount(0d);
        saleLine.setItemPrice(0d);
        salesLines.add(saleLine);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top