当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Ask delete confirmation only on last row

问题描述:

In my JSF application I have to delete rows from an employee table with other details. I am able to delete rows in the view, but I want to have a delete confirmation dialogue only on the last row deletion.

I have implemented it using JavaScript, but it pops up for every delete.

Now, I want it only for last row, I can check if it is last row through managed bean, but how this can be implemented in the view?

网友答案:

If you are displaying the table in the view you could use your js to check if there is only 1 row in the table when you click the delete button or however your deleting.

To do this you will need your html elements to have meaninful names, you can achieve this in jsf by using the id attribute in your view. You can then find the table $(#table-id) and see how many rows it has.

网友答案:

You can use the rows property of the HTML DOM <table> element to get all rows as an array on which you can invoke the length property to know about the length.

So, all with all, this should do:

<h:form id="form">
    <h:dataTable id="table" ...>
        <h:column>
            <h:commandButton value="delete" ...
                onclick="if (document.getElementById('form:table').rows.length == 1) return confirm('Are you sure?')" />
网友答案:

in your managed bean class before delete logic check table size.

  if(table.size == 1){
    popup = true;
   }

write another action that will called when Popups OK button clicked.

分享给朋友:
您可能感兴趣的文章:
随机阅读: