Reputation: 31
i tried using ajax/datable/codeigniter and i want to send my data in post like array data for example (search['value'] = searched_key).
function fetch_vtourdata( is_range_search, minPrice = '', maxPrice = '', minSurface = '', maxSurface = '', minNbRoom = '', maxNbRoom = '', searched_key = '')
{
var dataTable = $('#data_tableVtoursList').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"ajax":{
url: "../../website/userVtourTable",
type: "POST",
data: { 'user_id': user_id,
// 1 = name of POST, 2 = values
is_range_search:is_range_search,
minPrice:minPrice,
maxPrice:maxPrice,
minSurface:minSurface,
maxSurface:maxSurface,
minNbRoom:minNbRoom,
maxNbRoom:maxNbRoom,
search[{
'value':searched_key
}]
}
},
"columnDefs" : [
{
"target": [0, 3, 4],
"orderable": false,
}
]
});
$('#search').keyup(function(){
dataTable.search($(this).val()).draw();
});
}
Upvotes: 0
Views: 1135
Reputation: 31
my result is same than my first post just change :
search [{
'value' : searched_key
}]
by
searched_key: searched_key
define in your controller method :
if ( isset( $_POST['searched_key'] ) && !empty( $_POST['searched_key'] ) ) {
$_POST['search']['value'] = $_POST['searched_key'];
}
Upvotes: 1
Reputation: 518
Use the data table function and place the datable
dunction inside your javascript below your html, seperate the ajax data inside a controller
Could you tell more details about your problem ? like this
var oTable = $('#example').DataTable({
"ajax": "<?php echo base_url('dashboard/show_karyawan'); ?>",
"bDestroy": true,
"columns": [
{
"data": "id",
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{ "data": "NIP" },
{ "data": "nama" },
{ "data":"jabatan"},
{
"data": null,
"sDefaultContent": '<a href="" class="editor_view">view</a> / <a href="" class="editor_remove">Delete</a>'
}
]
});
I will suggest you use the newest Datatables, since there some function that wont work with the tutorial of datatables nowadays.
Upvotes: 0