laravel4-datatables-package icon indicating copy to clipboard operation
laravel4-datatables-package copied to clipboard

For multiple datatables which are using same url to fetch data with slightly difference in columns' order "order by" functionality is not working properly.

Open hardik-creolestudios opened this issue 11 years ago • 4 comments

For multiple datatables which are using same url to fetch data with slightly difference in columns' e.g. In below datatables check and compare columns and ajax properties. -> ajax properties url is same except one extra argument but they calls same method. -> column properties first columns are different. so while ordering it is not properly getting order ================ First ==================================== var tbl_reports = $('#tbl_reports').dataTable({ "bLengthChange": false, "processing": false, "serverSide": true, "ajax": "$id));?>", "bFilter": false, "columns": [ {"data": "name", "width": "15%", "name":"name" }, {"data": "reported_on", "width": "15%", "mRender": function(data, type, full) { return moment.utc(data).fromNow(); } }, {"data": "amount", "width": "15%", "mRender": function(data, type, full) { return "$"+data; } }, {"data": "bussiness_conduct", "width": "15%", 'sorting': false}, {"data": "disciplined_by", "width": "15%", 'sorting': false}, {"data": "details", "width": "5%", 'class': "alignCenter", 'sorting': false} ]

});

==========================Second================================

var tbl_reports = $('#tbl_reports').dataTable({ "bLengthChange": false, "processing": false, "serverSide": true, "ajax": "", "bFilter": true, "columns": [ {"data": "bussiness_name", "width": "15%"}, {"data": "name","width": "15%"}, {"data": "reported_on", "width": "15%", "mRender": function(data, type, full) { return moment.utc(data).fromNow(); } }, {"data": "amount", "width": "15%", "mRender": function(data, type, full) { return "$"+data; }, 'sorting': false }, {"data": "bussiness_conduct", "width": "15%", 'sorting': false}, {"data": "disciplined_by", "width": "15%", 'sorting': false}, {"data": "details", "width": "5%", 'class': "alignCenter", 'sorting': false} ]

});

hardik-creolestudios avatar Sep 19 '14 10:09 hardik-creolestudios

Can you please check following solution and tell is it proper or not ? Solution: -> Changed in ordering function of \vendor\bllim\datatables\src\Bllim\Datatables\Datatables.php

-> Please check edited code and old code which is comment in following code.

protected function ordering()
{
    if(array_key_exists('order', $this->input) && count($this->input['order'])>0)
    {
        $columns = $this->clean_columns( $this->last_columns );

        for ( $i=0, $c=count($this->input['order']); $i<$c ; $i++ )
        {
            $order_col = (int)$this->input['order'][$i]['column'];
            if (isset($columns[$order_col])) {
                if ( $this->input['columns'][$order_col]['orderable'] == "true" )
                {

                   #Old code#

                    //$this->query->orderBy($columns[$order_col],$this->input['order'][$i]['dir']);

                      #Old code#




                    #Edited code#

                    $this->query->orderBy($this->input['columns'][$order_col]['data'],$this->input['order'][$i]['dir']);


                    #Edited code#

                }
            }
        }

    }
}

hardik-creolestudios avatar Sep 19 '14 11:09 hardik-creolestudios

This fixed issue for me on column sorting when using ColReorder extension.

rustywebguy avatar Sep 22 '14 07:09 rustywebguy

@rustyfb24 Can you please show an snippet or any example link which shows how to use ColReorder extension ?

hardik-creolestudios avatar Sep 22 '14 08:09 hardik-creolestudios

You might want to look into the new dataFullSupport option in the latest version. There's a new example on using it in the docs. It relies less on the column order, and primarily on the column names set as the "data" property. It should allow you to return all the columns you need for both uses with the same url.

phazei avatar Oct 14 '14 01:10 phazei