Here is my javascript with flags
<script type="text/javascript">
$(document).ready(function() {
var dataTable = $("#example").DataTable( {
processing: true,
bSort: false,
serverSide: true,
iDisplayLength: 10,
"ajax": {
"url": "json/j-t.php",
"type": "POST"
},
} );
$("#example_filter").css("display","none"); // hiding global search box
$(".example-search-input").on("keyup click change", function () {
var ixoh =$(this).attr("id"); // getting column index
var vxoh =$(this).val(); // getting search input value
dataTable.columns(ixoh).search(vxoh).draw();
if(ixoh != null || ixoh != null){ dataTable.columns(ixoh).search(vxoh).draw(); };
} );
</script>
Here is the file j-t.php
$sql = "SELECT *";
$sql.=" FROM info WHERE type='1' AND sold='0'";
$query=mysqli_query($conn, $sql) or die;
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["types"];
$nestedData[] = $row["country"];
$nestedData[] = $row["infos"];
$nestedData[] = $row["price"];
$nestedData[] = $row["email"];
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
here is my database
SELECT * FROM `info` WHERE `country` LIKE 'CA' ORDER BY `date_added` DESC
I need to add in Datatables just like contry name CA US DE GB etc… i like to add with flags and Country name in Datatable Country row
2
Answers
You could download all of the SVG flags from a place like this …
https://observablehq.com/@slattery/iso-3166-svg-flags
… then add a column to your database that includes the name associated with your flag file, using an
ALTER TABLE info ADD COLUMN
query, followed by a bunch ofUPDATE
queries.Your PHP logic (or Twig, or Blade, or whatever you’re using) would then have to be edited to convert that name into an actual
<img>
tag for inclusion in the table.You can use column rendering as described here:
https://datatables.net/examples/advanced_init/column_render.html
In your case that would be something like:
For this example I commented out the server-side part and used some fixed HTML data. You can remove the comments for your use.