ncc1701e
ncc1701e

Reputation: 83

Javascript table click functions in Grails

If I have the following table:

enter image description here

I want one Controller function A invoked when the red dot is clicked on any row but function B invoked when the edit icon is click on any row.

I have successfully gotten one function to be invoked when clicking the red dot on any row with this javascript:

var myTable = document.getElementById('indivTble');

    if (myTable != null) {
        rows = myTable.getElementsByTagName('tr');
        var selectedUniqueId, selectedSecondaryId;  

        for (var i=1,len=rows.length; i<len; i++)   {
            rows[i].onclick = function() {
                selectedUniqueId = this.cells[2].innerHTML;
                selectedSecondaryId = parseInt(this.cells[3].innerHTML);
                <g:remoteFunction controller="customer" 
                                    action="editRecord" 
                                    update="flagsSummary" 
                                    params="{uniqueId: selectedUniqueId, secondaryId: selectedSecondaryId}"/>

but I am having trouble binding the second function to the edit icons which is:

<g:remoteFunction controller="customer" 
                                    action="displayRecordDetails" 
                                    update="flagsSummary" 
                                    params="{uniqueId: selectedUniqueId, secondaryId: selectedSecondaryId}"/>

I would greatly appreciate any help thanks.

Upvotes: 0

Views: 45

Answers (1)

user3914536
user3914536

Reputation:

Try this:

for (var i=1,len=rows.length; i<len; i++)   {

            rows[i].cells[0].onclick = function() {
                selectedUniqueId = this.parentNode.cells[2].innerHTML;
                selectedSecondaryId = parseInt(this.parentNode.cells[3].innerHTML);
                <g:remoteFunction controller="customer" 
                                    action="editRecord" 
                                    update="flagsSummary" 
                                    params="{uniqueId: selectedUniqueId, secondaryId: selectedSecondaryId}"/>
            }
        }
            for (var i=1,len=rows.length; i<len; i++)   {

            rows[i].cells[1].onclick = function() {
                selectedUniqueId = this.parentNode.cells[2].innerHTML;
                selectedSecondaryId = parseInt(this.parentNode.cells[3].innerHTML);
                <g:remoteFunction controller="customer" 
                                    action="displayRecordDetails" 
                                    update="flagsSummary" 
                                    params="{uniqueId: selectedUniqueId, secondaryId: selectedSecondaryId}"/>
            }
        }

Upvotes: 1

Related Questions