mgallegos / laravel-jqgrid

@Laravel jqGrid package allows you to easily integrate the popular @jQuery Grid Plugin (jqGrid) into your Laravel application.
mariogallegos.com
Other
69 stars 44 forks source link

filter toolbar search not working after hosted in domain #4

Closed sureshamk closed 10 years ago

sureshamk commented 10 years ago

Filter tool bar option is working fine in local . after i moved to hosted for live then i am not able get search result . but the query is posted .

mgallegos commented 10 years ago

How are you setting the URL property? Are you using the "URL::to" method?, like this:

setGridOption('url',URL::to('example/grid-data'))

sureshamk commented 10 years ago

Yeah Like this way only setGridOption('url',URL::to('example/grid-data'))

mgallegos commented 10 years ago

If the query is posted, using your browser developer tools, Do you see any errors?

sureshamk commented 10 years ago

I am used firebug to track server response ... its shows no error. I am getting status 200 response . I am compared with local and as well as hosted site. Both are working as same but hosted site return for grid's refreshed json ....

mgallegos commented 10 years ago

I don't what's going on, I haven't had that issue. But If it works fine locally maybe it's a server configuration problem.

mgallegos commented 10 years ago

And please make sure you are using the lastest version of the package.

Run "composer update"

ndcisiv commented 10 years ago

I am having the exact same problem. I can't get the search to work either. I'm running CentOS 5.10 (Final), Apache/2.2.8 (Unix), PHP 5.4.25 I can see the POST data being sent as such:

_search:true nd:1393451623441 rows:50 page:1 sidx: sord:asc filters:{"groupOp":"AND","rules":[{"field":"wo_comments","op":"cn","data":"mj"}]}

The response headers come back as:

Connection:Keep-Alive Content-Type:text/html; charset=UTF-8 Date:Wed, 26 Feb 2014 22:15:09 GMT Keep-Alive:timeout=15, max=97 Server:Apache/2.2.8 (CentOS) Transfer-Encoding:chunked X-Powered-By:PHP/5.4.25

The only thing I notice differently is that I've got a request cookie for laravel, but no response cookies. When I look at your online demo of the grid and do a search, I have no request cookies but two response cookies. If that helps.

ndcisiv commented 10 years ago

Out of curiosity, could it be a problem with using this package on Laravel 4.1?

mgallegos commented 10 years ago

@ndcisiv looking at the response headers I can assume that the server is completly ignoring the search parameters so the problem must be at the server side.

Can I see how did you implement the repository class (the class in charge of sending the response back to the client)?

ndcisiv commented 10 years ago

Here is the repository code

use Illuminate\Database\Eloquent\Model;
use Mgallegos\LaravelJqgrid\Repositories\EloquentRepositoryAbstract;

class ProductionRepository extends EloquentRepositoryAbstract {

    public function __construct() {
        $this->Database = new Production;
    }

    public function getTotalNumberOfRows(array $filters = array()) {
        return $this->Database->first()->all()->count();
    }

    public function getRows($limit, $offset, $orderBy = null, $sord = null, array $filters = array()) {
        return $this->Database->all()->toArray();
    }

}
mgallegos commented 10 years ago

ok I see the problem, if you are extending the "EloquentRepositoryAbstract" there is no need for you to implement the methods "getTotalNumberOfRows" and "getRows" because they have already been implemented by "EloquentRepositoryAbstract" class. As you can see in your code you are completely ignoring the the $filters array, that's is why is not working.

So all you have to do is delete both methods ( "getTotalNumberOfRows" and "getRows" ) an it will work, The "EloquentRepositoryAbstract" class do all the heavy lifting for you.

You can see how I did it in the source code of the demo:

https://github.com/mgallegos/laravel-jqgrid-demo/blob/master/app/Demo/Repository/InvoiceRepository.php

@sureshamk I hope this solve your problem too!

ndcisiv commented 10 years ago

HAH! You are absolutely correct! I apologize, this is my first time using Laravel (and jqGrid for that matter). I removed those two functions and am getting results now. Thank you.

I did notice that I had to add in visibleColumns and orderBy into the repository constructor for everything to show up properly and in the correct order, but it's working great now. Awesome work, thanks for making this available.

I do have one more question if it would be possible to do using this package. Is there a way to add an additional column to the grid with a checkbox of some kind inside so multiple rows could be selected, then have a button that when pressed could grab the values of the first column in the grid and send them off to be processed somehow?

I want to have the ability to select certain records then process those records further and output a report based on what's related to those records. It would display additional data that is NOT already included in the grid (calculations and such).

Again, thanks for the help.

mgallegos commented 10 years ago

Awesome work, thanks for making this available.

You are welcome!

Is there a way to add an additional column to the grid with a checkbox of some kind inside so multiple rows could be selected

Yes, set the following option:

->setGridOption('multiselect', true)

then have a button that when pressed could grab the values of the first column in the grid and send them off to be processed somehow?

So the to be able to that, set your HTML button to execute the following JavaScript function (let's assume the id of your grid is "example-grid"):

function processRecords()
{
   var idArray = [], row, columnName = 'id';

  $.each($('#example-grid').jqGrid('getGridParam', 'selarrrow'), function( index, value )
  {
      row = $('#example-grid').getRowData(value);       
      idArray.push(row[columnName]);
  });

 console.log(idArray);
 //Process idArray
}

You can do many things using the JqGrid JavaScript plugin methods, please take a look to the project documentation:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

Hope this helps!

bartvanenter commented 10 years ago

I have the same problem but i dont have the two functions in my repository

namespace Acme\Repository;

use Illuminate\Database\Eloquent\Model;
use Mgallegos\LaravelJqgrid\Repositories\EloquentRepositoryAbstract;

class RelationRepository extends EloquentRepositoryAbstract {

    public function __construct(Model $Model)
    {
        $this->Database = $Model;
        $this->visibleColumns = array('name','telephone');
        $this->orderBy = array(array('name', 'asc'), array('name','desc'));
    }

}

when i look in chrome developer tools i see that the request has been sent.. bui in my response i get all rows.

mgallegos commented 10 years ago

@niandralades can you post your view code ( GridRender:: ...)? I want to see how are you defining the grid columns.

bartvanenter commented 10 years ago

he, yes here it is

{{  
                    GridRender::setGridId("RelationGrid")
                    ->enablefilterToolbar()
                    ->setGridOption('url',URL::to('/relaties/griddata'))
                    ->setGridOption('autowidth',true)
                    ->setGridOption('height','100%') 
                    ->setGridOption('rowList',array(20,50,100,200, 1000))
                    ->setGridOption('iDisplayLength',100)
                    ->setGridOption('viewrecords',true)
                    ->setGridOption('modal',false)
                    ->setNavigatorOptions('navigator', array('viewtext'=>'view'))
                    ->setNavigatorOptions('view',array('closeOnEscape'=>false))
                    ->setFilterToolbarOptions(array('autosearch'=>true))                     
                    ->setNavigatorEvent('view', 'beforeShowForm', 'function(){alert("Before show form");}')
                    ->addColumn(array('label'=>Lang::get('general.name'),'index'=>'name', 'width'=>'65%'))
                    ->addColumn(array('label'=>Lang::get('general.telephone'),'index'=>'telephone', 'width'=>'25%','sortable' => false,'search' => false))
                    ->addColumn(array('label'=>'', 'name'=>'', 'index'=>'', 'width'=>'10%', 'align'=>'left','sortable' => false,'search' => false))
                    ->renderGrid();

                }}
mgallegos commented 10 years ago

@niandralades it seems you've done everything right, I don't know what's the problem. Take a look at source code of the demo: https://github.com/mgallegos/laravel-jqgrid-demo and try to look for something you've done different.

bartvanenter commented 10 years ago

i will... thanx for the fast response.. cant it also be a server issue?

Eslam87 commented 8 years ago

Following the tutorial "Building a Pivot Grid and handling jqGrid" i get an error. Laravel say to me $app is undefined. The piece of code that generate the problem is this : Route::post('/invoice-item-grid', function() use ($app) { GridEncoder::encodeRequestedData(new InvoiceItemRepository($app['db']), Input::all()); }); any way i want to do join query and some staff like that Model::find(1) Model::where('id','=',1) in Repositry file or any way to do that ?

mgallegos commented 8 years ago

For Laravel 5, do the following:

Route::post('/invoice-item-grid', function()
{
   $app = $this->app;
   GridEncoder::encodeRequestedData(new InvoiceItemRepository($app['db']), Input::all());
});

If the query you want to do is for showing data in the grid, you should do it inside the "Repository Class"(in this case, in InvoiceItemRepository)

tglx commented 8 years ago

Congratulations Mario for the Grid. I use Laravel 4.2.16. I want to query (from the server) the database filtered (e.g ->with('id_client','=','3')).

How could I send a POST parameter ?

Maybe method 1 ?

{{ GridRender::setGridId("myGrid") ->setGridOption('url',URL::to('/myLink-data-from-server')) }}

And the solution with something like ->setPostParameter('id_client','=','3') or ->setFilterParameter('id_client','=','3')

Maybe method 2 ?

Initialize the filter AND run the query (->renderGrid();) AND hide the filter and hide the entire column.

Thank you for your time & response ...

mgallegos commented 8 years ago

To send a POST parameter when the grid is created, we must simulate that we are using the filtered toolbar, in your case it should look like this:

->setGridOption('postData',array('filters'=>"{'groupOp':'AND','rules':[{'field':''id_client','op':'eq','data':'3}]}"))

In the turorial Building a Pivot Grid and handling jqGrid events you can see an example of how to work with parameters.

Eslam87 commented 8 years ago

I'm using custom form using Laravel jqGrid package what about server side validation ...I tried to do Request validation or class validator but not working any help please ?

tglx commented 8 years ago

THANK you Mario! It worked! + in your link (Building a Pivot ...), at Step 6 and row 12 I found the example!

tglx commented 8 years ago

I continue my scenario/situation: how do I keep the filter (WHERE id_client=3) when the user, complete in the FilterToolbar a value (and press Enter).

An other example, I have <?php GridRender::setGridId("myGrid") ->enablefilterToolbar(true, true) // show/create ToggleButton and show/create ClearButton ?>

And when the user (of the webpage) press the ClearButton (clear all the Filters completed by the user) I need to show the grid Filtered (WHERE id_client=3). (I repet the question) How do I keep the filter, in this situation ?

THANK you Mario for your TIME & response :-)

mgallegos commented 8 years ago

The tutorial also shows you what you need, the first step is to define the following javascript events:

function beforeClearEvent()
{
  $(this).jqGrid('setGridParam', {'postData':{"filters":"{'groupOp':'AND','rules':[{'field':'DEMO_Invoice.id','op':'eq','data':'" + $('#selectedInvoiceId').val() + "'}]}"}});
}

function afterClearEvent()
{
  //The id of all "filter toolbar" input text are formed by the prefix "gs_" and the column name.
  $('#gs_InvoiceId').val($('#selectedInvoiceId').val());
}

Then you need to add these events to your grid:

->setFilterToolbarEvent('beforeClear','beforeClearEvent')
->setFilterToolbarEvent('afterClear','afterClearEvent')

Hope this helps!