Convert date from JSON to Datatables - php

"tgl_dok":{"date":"2018-07-02 00:00:00.000000","timezone_type":3,"timezone":"Europe\/Berlin"}
jQuery code
$(document).ready(function(){
$('#table').DataTable({
"paging": true,
"lengthChange": true,
"searching": false,
"ordering": true,
"info": false,
"responsive": true,
"autoWidth": false,
"pageLength": 10,
"ajax": {
"url": "../adapter/ArReport/rptPenerimaanHarian/data.php",
type: "POST",
data: ({kd_entitas: kd_entitas,
tglAwal: tglAwal,
tglAkhir: tglAkhir})
},
"columns": [
{
title: 'Date',
data: "tgl_dok",
"type": "date",
},
{
title: 'Receipt. No',
data: "no_dok"
},
]
})
});
How can I show date format like DD/MM/YY in datatables?

UPDATE MyTable SET MyDate = CONVERT(datetime, '2018-07-02 00:00:00.000000', 121)
about convert rules look here

Related

disable sort icon in datatable not working for first column

I'm using "bSortable": false and "orderable": false but still sort asc icon visible in first column header. I have tried "bsort":false and "orderable": false, "targets": "_all" but still the icon is visible.
If i use "aaSorting":[] this it throws
Undefined variable: orderColumn
Mycode:
var test_table = $('#testDataTable').DataTable({
// "lengthMenu": [[10, 50, 100,150,200], [10, 50, 100,150,200]],
"lengthMenu": [[25, 50, 100], [25, 50, 100]],
"iDisplayLength": 25,
"sScrollX" : "100%",
"scrollX" : true,
"processing" : true,
"serverSide" : true,
"destroy":true,
"ajax" : {
url: "/test/datatable.php",
type: 'POST',
data: { status: 'ok' }
},
'columnDefs' : [{"searchable": true, "orderable": false, "targets": '_all' }, {"width": "12%", 'targets': [3,4,5] }]
});
Thanks in advance.
Change your code to this:
For me this works all the time ;)
var test_table = $('#testDataTable').DataTable({
// "lengthMenu": [[10, 50, 100,150,200], [10, 50, 100,150,200]],
"lengthMenu": [[25, 50, 100], [25, 50, 100]],
"iDisplayLength": 25,
"sScrollX" : "100%",
"scrollX" : true,
"processing" : true,
"serverSide" : true,
"destroy":true,
"ajax" : {
url: "/test/datatable.php",
type: 'POST',
data: { status: 'ok' }
},
"aoColumnDefs": [{ "bSortable": false, "aTargets": [ "_all" ] }],
"aaSorting": []
});

How to do server side sorting in data tables

I have used data tables in one of my project, all things are working fine except ordering, we want to use server side sorting, I tried lots of examples but it is not working for me,can anyone please help me to do sorting, I am stuck in this issue, here is my code
episodes_data_table = $('#episodes_table').DataTable({
"processing": true,
"serverSide": true,
"pageLength": 20,
"dom": 'trip<"clear">',
//"dom": 'trilp<"clear">',
"aaSorting": [[0, "desc"]],
"ajax": {
type: "post",
url: "<?php echo base_url(); ?>billing/get_episodes_data",
data: function (d) {
return jQuery.extend({}, d, {
"branch_id": current_branch_id,
"month": $(".month-filter-input").val(),
"year": $(".year-filter-input").val(),
});
}
},
"fnDrawCallback": function (oSettings) {
},
"columnDefs": [
{
"data": "ID",
"render": function (data, type, row) {
return data;
},
"targets": 0,
"visible": false,
"bSortable": false,
},
{
"data": "LastName",
"render": function (data, type, row) {
return data;
},
"targets": 1,
"visible": true,
"bSortable": false,
},
{
"data": "MRN",
"render": function (data, type, row) {
return data;
},
"targets": 2,
"visible": true,
"bSortable": false,
},
{
"data": "SOC",
"render": function (data, type, row) {
return data;
},
"targets": 3,
"visible": true,
"bSortable": false,
},
{
"data": "EpStart",
"render": function (data, type, row) {
return data;
},
"targets": 4,
"visible": true,
"bSortable": false,
},
{
"data": "EpEnd",
"render": function (data, type, row) {
return data;
},
"targets": 5,
"visible": true,
"bSortable": false,
},
{
"data": "PhyFirstName",
"render": function (data, type, row) {
return data;
},
"targets": 6,
"visible": true,
"bSortable": false,
},
{
"data": "SNVisits",
"render": function (data, type, row) {
return data;
},
"targets": 7,
"visible": true,
"bSortable": false,
},
{
"data": "HHAVisits",
"render": function (data, type, row) {
return data;
},
"targets": 8,
"visible": true,
"bSortable": false,
},
{
"data": "MSWVisits",
"render": function (data, type, row) {
return data;
},
"targets": 9,
"visible": true,
"bSortable": false,
},
{
"data": "PTVisits",
"render": function (data, type, row) {
return data;
},
"targets": 10,
"visible": true,
"bSortable": false,
},
{
"data": "OTVisits",
"render": function (data, type, row) {
return data;
},
"targets": 11,
"visible": true,
"bSortable": false,
},
{
"data": "STVisits",
"render": function (data, type, row) {
return data;
},
"targets": 12,
"visible": true,
"bSortable": false,
},
{
"data": "TotVisits",
"render": function (data, type, row) {
return data;
},
"targets": 13,
"visible": true,
"bSortable": false,
},
]
});
Can anyone please look at the code and give me the proper solution ? Any help will be really appreciated.

Kendo UI Grid HTML5 - Details Template Wont Save

This is the master grid
$(document).ready(function() {
$("#grid").kendoGrid({
height: 800,
sortable: true,
pageable: true,
selectable: "row",
filterable: {
mode: "row"
},
editable: { //disables the deletion functionality
update: false,
destroy: false
},
scrollable: true,
groupable: true,
pageable: {
pageSizes: [10, 25, 50, 100],
refresh: true,
buttonCount: 5
This is the subgrid, when I click the save button, it never make to the POST to the server. Is there a bug I have to make a event for make the POST?
function detailInit(e) {
// get a reference to the current row being initialized
var detailRow = e.detailRow;
detailRow.find(".subgrid").kendoGrid({
dataSource: {
transport: {
read: "./data/getDetails.php",
update: {
url: "./data/getDetails.php",
type: "POST"
}
},
schema: {
data: "data"
},
serverFiltering: true,
filter: {field: "candidate_id", operator: "eq", value: e.data.candidate_id}
},
sortable: true,
pageable: true,
selectable: "row",
height:300,
pageable: {
pageSizes: 5,
refresh: true,
buttonCount: 5
},
//rowTemplate: kendo.template($("#rowTemplate").html()),
columns: [
{title: "Task", field: "ARS",width: "100px",filterable: {
cell: {
showOperators: false
}
}},
{title: "Score", field: "Value",width: "250px"},
{ showOperators: false}
],
detailInit: detailInit,
editable: true,
navigable: true,
toolbar: [ "save", "cancel" ]
});
}
});
The back end is in php for fetech the query, I want to make the update.It arent working.
POSTMAN with POST to the API are working

my web app looks different on server and works perfectly on localhost

i'm using datatables with codeigniter
and it looked like this on localhost
datatables on localhost
and looked like this on server, i can't get the columns on the right side
even if i enabled scrollX
datatables on server
my java-script code
$(document).ready(function () {
var oTable = $('#tb').dataTable({
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
"autoWidth": false,
"colReorder": true,
"responsive": true,
"scrollX": true,
"sAjaxSource": '<?php echo base_url(roleURIUser()); ?>/leads/viewdata',
"bJQueryUI": false,
"sDom": 'T<"clear">Rlfrtip',
"tableTools": {
"sSwfPath": "<?= locationPlugin('url'); ?>datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf"
},
"sPaginationType": "full_numbers",
"iDisplayStart ": 10,
"aoColumns": [{
"mData": "name"
}, {
"mData": "mobile"
}, {
"mData": "phone"
}, {
"mData": "branch"
}, {
"mData": "code"
}, {
"mData": "email"
}, {
"mData": "university"
}, {
"mData": "faculty"
}, {
"mData": "address"
}, {
"mData": "date_created"
}, {
"mData": "status"
}, {
"mData": "comment"
}, {
"mData": "date_followup"
}],
"aoColumnDefs": [
{"bSearchable": false, "aTargets": [5, 6, 7, 8, 9, 10, 11, 12]},
{"bSortable": false, "aTargets": [5, 6, 7, 8, 9, 11, 12]},
{"width": "30%", "aTargets": [11]}
],
"order": [[0, "desc"]],
"oLanguage": {
"sProcessing": "<img src='<?= locationUpload('url'); ?>/ajax-loader.gif'>"
},
"fnInitComplete": function () {
//oTable.fnAdjustColumnSizing();
},
'fnServerData': function (sSource, aoData, fnCallback) {
$.ajax
({
'dataType': 'json',
'type': 'GET',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}
});
Check the image path of button next to your name.(+) and (-) image path.
I can not understand well at all.
If the problem is that you can not get the data on the server, check your config data in application/config/database.php
$db['default']['hostname'] = "host";
$db['default']['username'] = "username";
$db['default']['password'] = "password";
$db['default']['database'] = "database_name";
$db['default']['dbdriver'] = "mysqli";
If your CONECCION is correct, then the problem is in your model or your controller, eg
controller.php
function do_somthing(){
$this->load->library('database');
$this->load->model('model_file');
$info = $this->model_file->get_data();
var_dump($info);
}
model_file.php
function get_data(){
return $this->db->get('table')->result();
}

Data table not working in laravel

I try following code but its give error.
My code:
Dt = $('#mylist').dataTable({
"dom": "<'row no-gutters'<'col-md-4'l><'col-md-4'r><'col-md-4'f>>t<'row no-gutters'<'col-md-4'i><'col-md-4'><'col-md-4'p>>",
"processing": true,
"ajax": "{{ URL::to('product/list') }}",
"columnDefs": [
{"orderable": false, "targets": [3, 4]},
],
"order": [[0, "asc"]]
});
Try this:
You missed serverside : true in your code.
oTable = $('#mylist').dataTable({
"dom": "<'row no-gutters'<'col-md-4'l><'col-md-4'r><'col-md-4'f>>t<'row no-gutters'<'col-md-4'i><'col-md-4'><'col-md-4'p>>",
"processing": true,
"serverSide": true,
"ajax": "{{ URL('product/list') }}",
"columnDefs": [
{"orderable": false, "targets": [3, 4]},
],
"order": [[0, "asc"]]
});

Categories