Datatables external link and money currency, Thank You
Datatables external link and money currency, Thank You
Im trying to add external link to "customer_id" link example has to be like this /edit-customer.php?customer_id=$customer_id(which is link to original customer id)
I want to add '$' and money format has to be $ 1,250.00. this my code
// SCRIPT
$(document).ready(function(){
var dataTable = $('#customer_table').DataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"ajax" : {
url:"serverside/ajax-users.php",
type:"POST"
},
});
$('#customer_table').on('draw.dt', function(){
$('#customer_table').Tabledit({
url:'serverside/action.php',
dataType:'json',
columns:{
identifier : [0, 'customer_id'],
editable:[[1, 'customer_store', '{"1":"B2C","2":"B2B"}'],[2, 'customer_name'], [3, 'customer_address'], [4, 'customer_phone'], [5, 'customer_email'], [6, 'customer_status', '{"1":"Inactive","2":"Active"}']]
},
restoreButton:false,
onSuccess:function(data,textStatus, jqXHR)
{
if (data.action == 'delete')
{
$('#' + data.customer_id).remove();
$('#customer_table').DataTable().ajax.reload();
}
}
});
});
});
//SCRIPT
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Is this using Editor? Or some other editor?
Colin
its not editor, normal one. if you need all information is here. serverside
//AJAX-USER
<?inlcude your db
$column = array("customer_id", "customer_store", "customer_name", "customer_address", "customer_phone", "customer_email", "customer_status", "customer_date", "customer_order", "customer_sale");
$query = "SELECT * FROM customers ";
if(isset($_POST["search"]["value"]))
{
$query .= '
WHERE customer_id LIKE "%'.$_POST["search"]["value"].'%"
OR customer_name LIKE "%'.$_POST["search"]["value"].'%"
OR customer_store LIKE "%'.$_POST["search"]["value"].'%"
OR customer_address LIKE "%'.$_POST["search"]["value"].'%"
OR customer_phone LIKE "%'.$_POST["search"]["value"].'%"
OR customer_email LIKE "%'.$_POST["search"]["value"].'%"
OR customer_sale LIKE "%'.$_POST["search"]["value"].'%"
OR customer_status LIKE "%'.$_POST["search"]["value"].'%"
';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY customer_date DESC ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$statement = $connect->prepare($query . $query1);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
foreach($result as $row)
{
$sub_array = array();
}
function count_all_data($connect)
{
$query = "SELECT * FROM customers";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
$output = array(
'draw' => intval($_POST['draw']),
'recordsTotal' => count_all_data($connect),
'recordsFiltered' => $number_filter_row,
'data' => $data
);
echo json_encode($output);
//AJAX-USER
//ACTION
if ($_POST['action']== 'edit') {
}
if ($_POST['action'] == 'delete')
{
$query = "
DELETE FROM customers
WHERE customer_id = '".$_POST["customer_id"]."'
";
$statement = $connect->prepare($query);
$statement->execute();
echo json_encode($_POST);
}
//ACTION
See the
columns.render
docs for an example of creating a link. You can use a number renderer to format the number output.Kevin
Thanx Kevin I solved, external link like this. but i have still problem for money currency.
"columnDefs": [ {
"targets": 10,
"data": 0,
"render": function ( data, type, row, meta ) {
return '<button class="btn btn-light btn-sm"><a href="/edit-customer.php?customer_id='+data+'">Detail</a></button>';
}
} ]
for money currency.
data: 9,
render: $.fn.dataTable.render.number( ',', '.', 2, '$' ),
i dont know where am i gonna put this. bcs when i added under columnDefs is working but this time hyperlink is not showing.
"columns":[{
targets : 4,
dataSrc : null,
render: $.fn.dataTable.render.number( ',', '.', 2, '$ ' )
}],
can you please help me with this. I am putting this code and ID numbers shows money format. i wanna change column-4 .
this is the money rendering solution. thank you
let dataTable = $('#product_table').DataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"ajax" : {
url:"serverside/ajax-products.php",
type:"POST"
},
"columnDefs": [
{
"targets": 6,
"data": 0,
"render": function ( data, type, row, meta ) {
return '<center><button class="btn btn-sm"><a href="/edit-product.php?product_id='+data+'">Detail</a></button></center>';},
},
{
"targets": 4,
"data": 4,
"render": $.fn.dataTable.render.number(',', '.', 2, '$ ')
}
],
});