Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically adding a row to primefaces dataTable

Tags:

jsf

primefaces

I need to add a row to my datatable on click of a button - "Add Employee".

The datatable shows the records corresponding to a fixed list of Employees in the bean.

What I am doing is, on click of the "Add Employee" button , I am adding an empty record of Employee to the empList.

Is there any better way to do this?

Thanks.

like image 743
Shikha Dhawan Avatar asked Mar 05 '12 05:03

Shikha Dhawan


People also ask

How to Add Row IN primefaces dataTable?

A new row can be added by clicking the Add new button.

What is RowKey in Primefaces?

RowKey should be a unique identifier from your data model and used by datatable to find the selected rows. You can either define this key by using the rowKey attribute or by binding a data model which implements org. primefaces.


1 Answers

Either you open a dialog or a popup when clicking the add button. Then fill in the required fields (attached to a employee object. And when saving/submit you add that object to your list of employee objects. And rerender the datatable. Or you can initially add an empty emploee object to your list. Showing it in the datatable with inputfields. On add, you add the new employee to the list and rerender the list.

like image 169
roel Avatar answered Oct 30 '22 14:10

roel