我想使用DataTable.js API向表中显示hindi或gujarati数据。 我有以下javascript代码:
$(document).ready(function(){
// On page load: datatable
var url = "<?php echo base_url();?>list?job=get_companies";
var table_companies = $('#table_companies').dataTable({
"ajax": url,
"lang": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Gujarati.json",
"language": {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Gujarati.json"
},
"columns": [
{ "data": "id" },
{ "data": "text", "sClass": "Text" },
{ "data": "userid" }
],
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [-1] }
],
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"oLanguage": {
"oPaginate": {
"sFirst": " ",
"sPrevious": " ",
"sNext": " ",
"sLast": " ",
},
"sLengthMenu": "Records per page: _MENU_",
"sInfo": "Total of _TOTAL_ records (showing _START_ to _END_)",
"sInfoFiltered": "(filtered from _MAX_ total records)"
}
});
});
然后我得到了来自php文件的响应看起来像(数组有三个参数,数据有hindi或Gujarati数据格式的字符串,如何使用dataTable.js设置数据):
$data = array(
"result" => $result,
"message" => $message,
"data" => $mysql_data
);
// Convert PHP array to JSON array
$json_data = json_encode($data);
print $json_data;