Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on 

Could you point how to disable buttons by using jQuery depending on a bale column value?

Hi Experts

Could you point how to disable buttons by using jQuery depending on a bale column value?

Accordingly to

User generated image
When the column value of the Staus column is "Concluido" the buttons must to be disabled.

PHP
<td>
	<a href="http://<?php echo APP_HOST; ?>/produto/edicao/<?php echo $produto->getId(); ?>" class="btn btn-info btn-sm">Editar</a>
	<a href="http://<?php echo APP_HOST; ?>/produto/exclusao/<?php echo $produto->getId(); ?>" class="btn btn-danger btn-sm">Excluir</a>
</td>

Open in new window


jQuery (using previous reply)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
	$('.table tr').each(function(i,e) {
		if ($('td:eq(4)', this).text() == 'Concluido') {
			$(this).css({backgroundColor: 'green'});

                         // It doesn't works
                         $('.btn btn-info btn-sm').prop('disabled', false);
                         $('.btn btn-danger btn-sm').prop('disabled', false);

		}
	});
});
</script>

Open in new window


Thanks in advance!
PHPjQuery

Avatar of undefined
Last Comment
Eduardo Fuerte
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Firstly, if you want your button to be disabled, then you need to set the disabled property to true, not false.

Secondly, you will need to give the selector a context so that it finds the button within the current row. The code to disable your buttons for the specific row would be:

$('.btn', this).prop('disabled', true);
Avatar of Eduardo Fuerte

ASKER

So I attempted this:

<td>
	<a href="http://<?php echo APP_HOST; ?>/produto/edicao/<?php echo $produto->getId(); ?>" class="btn btn-info btn-sm">Editar</a>
	<a href="http://<?php echo APP_HOST; ?>/produto/exclusao/<?php echo $produto->getId(); ?>" class="btn btn-danger btn-sm">Excluir</a>
</td>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$(function() {
	$('.table tr').each(function(i,e) {
		if ($('td:eq(4)', this).text() == 'Concluido') {
			$(this).css({backgroundColor: 'green'});
            
                       $('.btn', this).prop('disabled', true);

                  //$('.table btn', this).prop('disabled', true);
            
		}
	});
});
</script>

Open in new window


It doesn't works out. I guess something else is needed.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Eduardo Fuerte

ASKER

@Chris

Very good solution!

Thank you very much!
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo