0
Good morning, I’m trying to use a datatable filters but the filters disappear when this code enters:
<td style="display:none;" class="id_<?=$row['id']?>"><?php echo $row['id']; ?></td>
<td class="text-right">
<input name="comprar" id="comprar" value="Comprar" class="comprar btn btn-success" type="submit" coluna="<?=$row['id']?>"></input>
</td>
When I remove the code above, the filters appear again:
I need the filters to appear without having to remove the code above.
Code (filters do not appear) :
<div class="content">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">COMPRAR PRODUTOS :: </h4>
</div>
<div class="card-body">
<div class="toolbar">
<!-- Here you can write extra buttons/actions for the toolbar -->
</div>
<table id="datatable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>PREÇO</th>
<th>VENDEDOR</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>PREÇO</th>
<th>VENDEDOR</th>
</tr>
</tfoot>
<tbody>
<?php foreach ($resultado as $row) { ?>
<tr>
<td style="display:none;" class="id_<?=$row['id']?>"><?php echo $row['id']; ?></td>
<td class="seis_<?=$row['id']?>"><?php echo substr($row['cc'], 0, 6); ?></td>
<td class="preco_<?=$row['id']?>"><?php echo $row['PRECO']; ?></td>
<td class="vendedor_<?=$row['id']?>"><?php echo $row['Vendedor']; ?></td>
<td class="text-right">
<input name="comprar" id="comprar" value="Comprar" class="comprar btn btn-success" type="submit" coluna="<?=$row['id']?>"></input>
</td>
</tr>
<?php } ?>
Code (filters showing up):
<div class="content">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">COMPRAR PRODUTOS ::</h4>
</div>
<div class="card-body">
<div class="toolbar">
<!-- Here you can write extra buttons/actions for the toolbar -->
</div>
<table id="datatable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>PREÇO</th>
<th>VENDEDOR</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>PREÇO</th>
<th>VENDEDOR</th>
</tr>
</tfoot>
<tbody>
<?php foreach ($resultado as $row) { ?>
<tr>
<td class="seis_<?=$row['id']?>"><?php echo substr($row['cc'], 0, 6); ?></td>
<td class="preco_<?=$row['id']?>"><?php echo $row['PRECO']; ?></td>
<td class="vendedor_<?=$row['id']?>"><?php echo $row['Vendedor']; ?></td>
</tr>
<?php } ?>
Javascript code:
<script>
$(document).ready(function() {
$('#datatable').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
responsive: true,
language: {
search: "_INPUT_",
searchPlaceholder: "Search records",
}
});
var table = $('#datatable').DataTable();
// Edit record
table.on('click', '.edit', function() {
$tr = $(this).closest('tr');
var data = table.row($tr).data();
alert('You press on Row: ' + data[0] + ' ' + data[1] + ' ' + data[2] + '\'s row.');
});
// Delete a record
table.on('click', '.remove', function(e) {
$tr = $(this).closest('tr');
table.row($tr).remove().draw();
e.preventDefault();
});
//Like record
table.on('click', '.like', function() {
alert('You clicked on Like button');
});
});
</script>
To start, take the <input... the </input> closure from the tag. This usually causes problems, in the initial frame where you noted '<input name="buy" id="buy" value="buy" class="buy btn btn-Success" type="Submit" column="<?= $Row['id']? >"></input>'. You should only get <input name="buy" id="buy" value="buy" class="buy btn btn-Success" type="store" column="?= $Row['id']?>" />
– user4701