Button Status

Button Status

Hildeb67Hildeb67 Posts: 85Questions: 23Answers: 1

Hello everyone,
I want to read the status of the button at the front in a line. Whether it contains a plus or minus sign. Is that possible?

Greetings, Chris

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,983Questions: 26Answers: 5,077

    It is possible. Use cell().node() to get the td then use jQuery or Javascript methods to parse the button to get the plus or minus status. If you need specific help with this then please provide a simple test case showing how the buttons are built into HTML so we can offer more specific suggestions.

    Kevin

  • Hildeb67Hildeb67 Posts: 85Questions: 23Answers: 1

    a test case is not possible to create because it is an online project
    this is how the button is triggered

            tablefzg.on('click', 'button', function (e) { 
                var action = this.className;
    
                if (action=='GetFZG'){                                                  
                    if (this.innerHTML == '-') {
                        this.innerHTML = "+";                   
                        this.style.backgroundColor = '#F0F0F0';     
                         
                    } else if (this.innerHTML == '+') {               
                        this.innerHTML = "-";                                           
                        this.style.backgroundColor = '#60c724';                         
                    }
                }
            })  
    

    Are there any examples of this?

    Chris

  • kthorngrenkthorngren Posts: 21,983Questions: 26Answers: 5,077

    Does that code work?

    The best thing to do is to start with this template:
    https://live.datatables.net/

    Refactor the template to show the buttons in the first column. Add your click event handler and provide details of what isn't working and what you want the event handler to do.

    This will allow us to see exactly what you have and what isn't working so we can offer specific suggestions.

    Kevin

  • Hildeb67Hildeb67 Posts: 85Questions: 23Answers: 1

    Kevin I wrote you a private email

  • kthorngrenkthorngren Posts: 21,983Questions: 26Answers: 5,077
    Answer ✓

    I copied this code into the console of your page:

    let fzgTable = $('#fzg').DataTable();
    
    fzgTable.on('click', 'tbody tr td input.GetKM', function () {
        let row = $(this).closest('tr');
        let button = $('button.GetFZG', fzgTable.cell( row.index(), 4 ).node());
        alert( 'Button has: ' + $(button).html() );
    });
    

    This seems to work.

    Kevin

  • Hildeb67Hildeb67 Posts: 85Questions: 23Answers: 1

    Great Kevin, thank you very much, that works

Sign In or Register to comment.