This discussion is archived
2 Replies Latest reply: Nov 2, 2012 3:40 AM by 894578 RSS

Adding row after clicking on a non-initialized row

894578 Newbie
Currently Being Moderated
Hi,

I need to be able to add a new row to the table view after clicking on the first non- initialized row

For example:

If I have an empty table instead of displaying: “No content in table”
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
First Name | Last Name | Email |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
No content in table <font color="white">-------------------</font>|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

I need to add a row which contains “Click to add”. when the user click on it, a new editable row will be added to the tableview

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
First Name | Last Name | Email |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Click to add | <font color="white">----------------</font> |<font color="white">--------</font> |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

And in case the table view control contains some items, I need to add “Click to add ” on the first non-initialized row

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
First Name | Last Name | Email |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Firs tName 1 | Last Name1 | Emai l 1 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
First Name 2 | Last Name2 | Emai l 2 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
First Name 3 | Last Name3 | Emai l 3 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Click to add | <font color="white">----------------</font> |<font color="white">--------</font> |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Could you please advice on the way to add this functionality?
  • 1. Re: Adding row after clicking on a non-initialized row
    RichardBair Journeyer
    Currently Being Moderated
    There are a couple ways you can do this. Perhaps the easiest would be to just have a custom cell editor for the first column. Every cell has a TableColumn and a row index associated with it. What you need to do is make sure your ObservableList of data items for the table has an extra item at the ended which is a special marker so that when you are creating the cell for that row, you know to deal with it specially.

    So the key things to look at and familiarize yourself with: ability to customize cells, how items are mapped to cells. Then the trick is just to add a special "new row item" to your items list so your custom cell can handle it specially.
  • 2. Re: Adding row after clicking on a non-initialized row
    894578 Newbie
    Currently Being Moderated
    Hi Richard,

    Thanks for your answer
    I have a question about : [What you need to do is make sure your ObservableList of data items for the table has an extra item at the ended which is a special marker so that when you are creating the cell for that row, you know to deal with it specially]

    The disadvantage of the above is that tableView.getItems() will always return an additional "not wanted" item (the last item). Note that I'm unable to override getItems() method since it is final. Any Suggestions?

    Thx,

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points