Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add custom columns to dataTables with server-side processing?

i have made this example work on my page http://datatables.net/examples/server_side/server_side.html, (using php5, jquery+ui and dataTables.net)

i would like to be able to add a Modify and Delete link on each row, how can i do that without sending two extra columns with the links from the server?

also how can i substitute the ids the rows have in the database and that are sent by the server with nice number starting from 1 till iTotalDisplayRecords...

thank you

like image 501
max4ever Avatar asked Oct 13 '22 18:10

max4ever


1 Answers

found how

var controller_name = '<?php echo Zend_Controller_Front::getInstance()->getRequest()->getControllerName();?>';


"fnDrawCallback": function ( oSettings ) {
                    /* Need to redo the counters if filtered or sorted */

                        for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
                        {
                            var link = $('&nbsp;<a href="/'+controller_name+'/modifica/id/'+ oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[0]+'">Modifica</a> <a href="/'+controller_name+'/cancella/id/'+ oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[0]+'">Cancella</a>');
                            $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
                            $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).append(link);
                        }
                },
like image 142
max4ever Avatar answered Oct 31 '22 22:10

max4ever