Question: I am using Laravel 4.2, with server side jQuery data-tables.

Package: <https://github.com/Chumper/Datatable>

How can I add custom sorting ?

like for columns of currency, time, etc

Answer: 
this is how I do it

n.b. it's not optimized. more or less a complete code snippet without error checking

laravel controller function (it's L5.2 but easily downgrade-able to 4.2):

```
    $response = array();
    $query = MyModel::query();

    $response['recordsTotal'] = MyModel::count();
    $response['draw'] = Input::get('draw', 0);

    $query->where('searchField', 'LIKE', '%' . Input::get('search', array('value' => ''))['value'] . '%');
    $response['recordsFiltered'] = $query->count();

    $query->take(Input::get('length', 1));
    $query->offset(Input::get('start', 0));

    $columns = Input::get('columns');
    $orders = Input::get('order', []);

    $data = $data->toArray();
    foreach($orders as $order){
        $idx = $order['column'];
        $column = $columns[$idx];

        $orderFactor = 1;
        if($order['dir'] == 'desc')
            $orderFactor = -1;
        $dname = $column['data'];
        if(count($data)>0){
            if(isset($data[0][$dname])){
                usort($data, function($record1, $record2) use($dname, $orderFactor){
                    // here you implement your custom sorting
                    // like if($dname === 'price') return compare_price($record1[$dname], $record2[$dname]) * $orderFactor; 
                    // but I hope you're not storing prices as strings in your database. you won't need this custom sorting
                    //
                    return strcmp($record1[$dname], $record2[$dname]) * $orderFactor;
                });
            }
        }
    }
    $response['data'] = $data;
    return Response::json($response);

```

p.s. this code assumes that the 'data' field of the datatable columns is named exactly as the field name in your database.
You will also need to use a render\_function to render the datatable column as you wish

datatable columns:

```
columns: [
    { data: 'price', orderable: true, searchable: true, render: render_price },
    { data: 'anotherField' },
    [...]
],

```

render\_function example:

```
    function render_price(price, type, row) {
        return price + ' USD';
    }

```

this way you will have your datatable displaying columns the way you want (e.g. price = 10.50$)

and they will be sortable
Haven't you checked the documentation? Because it's explained there:

```
public function getDatatable() { return Datatable::collection(User::all(array('id','name'))) ->showColumns('id', 'name') ->searchColumns('name') ->orderColumns('id','name') ->make(); }

```