Laravel: sending JSON - jqgrid - How?

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 17
Joined: Fri Oct 30, 2015 4:13 am

Thu Dec 03, 2015 2:31 pm

Hi there,

I'm trying to populate jqgrid from database. I've jqgrid.
Laravel 4.2
I'm unable to send json data back to browser. No error, or anything.
I've data pulled from DB, made it into json format.

I'm going to post 4 code snippets:
1. jqgrid
2. routes.php -relevant
3. controller - used
4. model - used

I've a jqgrid whose code:

Code: Select all


		datatype: "json",
		contentType: "application/json", 
		mtype: "GET",		
		jsonReader: {
		    repeatitems: false,
		    id: "",
		    root:  function (obj) {
		        return obj;
		    records: function (obj) {
		        return obj.length;
		    page: function () {
		        return 1;
		    total: function () {
		        return 1;
		colNames:['study','Sample Name','Forward Primer','Reverse Primer'],
        colModel :[ 
                   {name:"study",sortable: true}, 
                   {name: "sample_name",sortable: true},
                   {name: "forward_primer",sortable: true},
                   {name: "reverse_primer",sortable: true}
                rowNum:10, //this sets the default row in the pager
            caption:"Illumina", //title of the grid
			pager: '#pager_illumina',	
   			shrinkToFit : false,
   	        rownumbers: true, //row numbers on left
   	        multiselect: true, //check box
   			height: '400', //height: 'auto',
   			width: '1100',
   			gridview: true,			
   			viewrecords:true, // this is for the View 1 - 8 of 8 \m/
   			sortorder:"asc", //asc 
   			autoencode: true, //don't know
   			sortable:true, //sort
   			loadonce: false, //loadonce is must
   			rowList:[500,1000,1500], //drop down
   			page: 1,
   			rowNum: 100

Code: Select all

Route::group(['prefix' => 'illumina', 'namespace' => Controllers\\illumina','before' => 'auth'], function() {

//send to controller
	Route::get('illumina_xhr_get_data','mainIllumina@get_illumina_data'); //called from js->illumina->grid.js
	//add functoin for Route::ajax 		
Controller function:

Code: Select all

	public function get_illumina_data(){
		(new illumina_model())->get_data(); //get rows from illume table
Model code

Code: Select all

	public function get_data(){
		$illumina_sample = DB::connection('illumina')->table(
		//grab all sample rows
		return Respose::json($illumina_sample);
I've output from the JSON as:
Cache-Control: no-cache
Content-Type: application/json
Date: Thu, 03 Dec 2015 22:27:15 GMT


In my small application, in model I simply had to
echo json_encode($rows_pulled)

And that would populate my same grid. However, here I'm clueless.
I think response has to be sent from model in laravel too. Please correct me if I'm wrong.
How do fix it?
Any help shall be highly appreciated.

Post Reply