I was reading AliDatatableBundle but didn't find anything helpful so here is my problem. This is the code in my _datatable
function:
private function _datatable()
{
return $this->get('datatable')
->setEntity("ComunBundle:SolicitudUsuario", "su")
->setFields(
array(
"Tipo de Tramite" => 'tt.nombre',
"No. Solicitud" => 'su.id',
"Tipo de Solicitud" => 'tr.nombre',
"Estado" => 'es.nombre',
"Fecha" => 'su.fecha_creacion',
"_identifier_" => 'su.id')
)
->setWhere('su.usuario = :usuario', array('usuario' => $this->get('security.context')->getToken()->getUser()->getId()))
->addJoin('su.tipo_tramite', 'tt', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
->addJoin('su.tipo_registro', 'tr', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
->addJoin('su.estado_solicitud', 'es', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
->setOrder("su.fecha_creacion", "DESC")
->setHasAction(true);
}
As you may notice there is fecha_creacion
field which returns to the view this [object Object]
I'm suspecting it's a DateTime so I need to format it before send to the render/view but I have not idea in how to, any advice? I don't know if Custom Rendering as explained here is the solution but if it's I still having no idea around it. Any help?
The problem you are facing in AliDatatableBundle can be resolved by making use of https://github.com/AliHichem/AliDatatableBundle#-doctrine-query-builder where you can write your symfony2 custom query making use of Doctrine.
And rendering the date object in the under twig file location (ali/datatable/Ali/DatatableBundle/Resources/views/Main/index.html.twig) by making use of aoColumnDefs you can see my example below in order to render date object in first column of your data table.
var $defaults = {
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aLengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, "All"]],
"iDisplayLength": 10,
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": null,
"bPaginate": true,
"bLengthChange": false,
//"aoColumnDefs": $aoColumnDefs, // you can comment this default one and write your own aoColumnDefs
"aoColumnDefs": [
{"aTargets": [0],"fnRender": function(dateobject){ return dateobject.aData[0].date }},
{"aTargets": [1],"fnRender": function(profile){
//making decision based on different row data
if(profile.aData[1] == 1)
return 'Admin';
else if(profile.aData[1] == 2)
return 'Consumer';
else
return 'Vendor';
}
},
{"aTargets": [2],"fnRender": function(name){
var $edit_url = strtr(
"{{ path(edit_route , { 'id': "xx" }) }}",
{ "xx": name.aData[{{fields|length}}-1] }
);
return "<a style='float:right; margin-right:10px' class='dialog' title='edit'href='"+$edit_url+"'>"+name.aData[2]+"</a>";
}
}
],
"fnDrawCallback": function(oSettings) {
var s = getWrapper();
if( multiple && $('.dataTables_multiple',$(s)).length==0){
$(s+' .dataTables_length').prepend(multiple_rawhtml);
}
},
"bSort": true,
"bFilter": {% if search %} true {% else %} false {% endif %},
"oLanguage": {
"sProcessing": '{{ 'Processing' | trans() }}',
"sLengthMenu": '{{ 'LengthMenu' | trans() }}',
"sZeroRecords": '{{ 'ZeroRecords' | trans() }}',
// "sInfo": '{{ 'Info' | trans() }}',
// "sInfoEmpty": '{{ 'InfoEmpty' | trans() }}',
"sInfoFiltered": '{{ 'InfoFiltered' | trans() }}',
// "sInfoPostFix": '{{ 'InfoPostFix' | trans() }}',
"sSearch": '{{ 'Search' | trans() }}',
"sLoadingRecords": '{{ 'LoadingRecords' | trans() }}',
"sUrl": "",
"oPaginate": {
"sFirst": '{{ 'First' | trans() }}',
"sPrevious": '{{ 'Previous' | trans() }}',
"sNext": '{{ 'Next' | trans() }}',
"sLast": '{{ 'Last' | trans() }}'
}
},
"bAutoWidth" : false
};
You can also set different twig files inside location (ali/datatable/Ali/DatatableBundle/Resources/views/Main) to have different twig files. In your ownbundle twig file supply the argument main_template
{{ datatable({ 'edit_route' : 'RouteForYourEntity_edit', 'delete_route' : 'RouteForYourEntity_delete', 'main_template' : 'AliDatatableBundle:Main:myfile.html.twig', 'js' : { 'sAjaxSource' : path('RouteForYour_grid_action') } }) }}