bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

how about nested queries? #157

Closed lgt closed 10 years ago

lgt commented 10 years ago

How would I build my datatable if my query with Laravel DB looks like :

    $results = DB::select('
                SELECT 
                        publisher_name, 
                        SUM(sales) AS sales, 
                        SUM(comission) AS comission, 
                        SUM(sale_total) AS publisher_total_sale,
                        sumOfTotalSales
                FROM reports_summary,
                        (SELECT SUM(sale_total) AS sumOfTotalSales FROM reports_summary) AS subTotalSales
                WHERE campaign = ?   
                   GROUP BY publisher_name, sumOfTotalSales 
                   ORDER BY publisher_total_sale DESC', array($campaign));
ktunkiewicz commented 10 years ago

This class is designed to handle "Eloquent ORM or Fluent Query Builder" objects (see Readme.md). You use DB::select which is simply a raw database access function.

You must create your query using Query Builder ( http://laravel.com/docs/4.2/queries#selects ) and then use the created object with this class.

Example:


// create query builder object
$users = DB::table('users')->select('name', 'email');

// use it with Datatables class
$output = Datatables::of($users)->make();

The "issues" section of this website is definitly not the place where you should ask the question "how to" use Query Builder... Issues section is for reporting bugs, etc. Please post your question to Stack Overflow or similar. You can put a link to stackoverflow question here if you want us to help you too.

lgt commented 10 years ago

okay thanks, sorry but I did not saw mentioned that I can pass the query to Datatable like that. The query alone is working fine