0

I am having a datatable with id employeeDataTable and inside that I have commandbuttons as column like below

<p:commandButton value="Me" update=":#{p:component('primaryEmployeeDetails')}" id="ajax"
     actionListener="#{userPreferenceBean.saveEmployee}" styleClass="ui-priority-primary">
     <f:param name="employeeName" value="#{employee.name}" />
</p:commandButton>

I want to get the control of all commandbuttons so that I can do operation on those inside Jquery. This is what I am doing --

 $(document).ready(function() {
        $(".ui-priority-primary").click(function() {
        //Getting all rows to iterate through them
        var row = $(document.getElementById("myForm:employeeDataTable")).find("tbody:first").children("tr");
        row.each(function() {
            alert('inside row');
            $(this).find('td').each(function(){
                   alert('inside each cell')
            });
        });
     });

Both alert's are working fine. But can you tell me how to get all commandbutton references in the second loop? Thanks.

Sudipta Deb
  • 1,040
  • 3
  • 23
  • 43
  • Why the previous comments are getting deleted? – Sudipta Deb Sep 17 '13 at 16:24
  • I just deleted my own answer. Because, after all, the question isn't asking what you actually needed and you asked a new, completely different, question in a comment of my answer. Your question is asking how to get the refrence of command button inside the loop. However, after all, you somehow actually needed all command buttons instead of the referenced one. But you already know how to do that (otherwise you wasn't able to create `click` function). After all, the whole question is wrongly formulated and completely useless. I didn't find it worth the effort to keep my answer in nor to edit it. – BalusC Sep 17 '13 at 16:46
  • Got your point @BalusC. I have managed to get all commandbutton references. Thanks. I don't agree about the point you said that the question is useless. It is a good learning for beginners like me to get more familiar with JQuery. – Sudipta Deb Sep 17 '13 at 16:56
  • You **did not** ask how to get all command buttons. In at least 3 places of the question you explicitly mentioned in some way that you only want to get the current reference. You did not said "references". You did not said "controls". You did not said "commandbuttons". In other words, the question is wrong. My answer was valid, but not what you actually asked after all. As long as you don't fix the question, no one with a basic understanding of English will be able to post the right answer. – BalusC Sep 17 '13 at 16:57
  • @BalusC: Updated the question. Sorry for the problem – Sudipta Deb Sep 17 '13 at 17:00

1 Answers1

0

Finally able to achieve the functionality with below code. A special thanks to @BalusC for guiding me. Sharing the answer here.

$(document).ready(function() {
        $(".ui-priority-primary").click(function() {
            var buttons = $(".ui-priority-primary");
            var rows = $(document.getElementById("myForm:employeeDataTable")).find("tbody:first").children("tr");
                rows.each(function() {
                      alert('Inside Row Loop');
                });

                $(buttons).each(function(){
                      $(this).doUserOperation();
                });
        });
});
Sudipta Deb
  • 1,040
  • 3
  • 23
  • 43