I am using a laravel-jqgrid library of "mgallegos/laravel-jqgrid"
. When using query builder it works fine, but my requirement is to use raw queries.
How can I handle that?
Here are my codes:
GridRepository.php:
namespace Repositories;
use \Illuminate\Support\Facades\DB;
use App\App;
use Mgallegos\LaravelJqgrid\Repositories\EloquentRepositoryAbstract;
class GridRepository extends EloquentRepositoryAbstract {
public function __construct($db_obj, $columns, $order_by)
{
$this->Database = $db_obj;
$this->visibleColumns = $columns;
$this->orderBy = $order_by;
}
}
GridController:
class JqGridController extends Controller {
protected $GridEncoder;
public function __construct(RequestedDataInterface $GridEncoder)
{
$this->GridEncoder = $GridEncoder;
}
public function getIndex()
{
return View::make('grid-apps');
}
public function postGridData()
{
$db_obj = DB::table('applications')
->join('branches', 'applications.branchid', '=', 'branches.id')
->whereNotIn('applications.status', ['Reject', 'Rejected', 'Deleted']);
$columns = array('applications.status','branches.name as branches.name', 'applications.created_at as applications.created_at', 'applications.amount');
$order_by = array(array('applications.created_at', 'asc'));
$this->GridEncoder->encodeRequestedData(new GridRepository($db_obj, $columns, $order_by), Input::all());
}
}
In search option of jqgrid I have added following code:
searching: {
closeAfterSearch: true,
closeAfterReset: true,
closeOnEscape: true,
searchOnEnter: true,
multipleSearch: true,
multipleGroup: true,
showQuery: true,
afterShowSearch: function(event){
console.log('event', event);
$(document).find('.add-group').hide();
}
}
How can I achieve that using a raw query? Because we were using Ajax datatable on raw query there are 100s of tables made from datatables. Now we are moving to jqgrid, so we want less changes to move.