views:

43

answers:

1

1)

I am using the jqgrid plugin to show results from different selections a user can make on sliders and such. The jqgrid loads via a php command:

$grid->SelectCommand = 'MySQL SELECT statement here';

But I want to change this, and reload the data at runtime (via jquery) when the user makes a change.

(Also if possible I would like to know the number of results found so I can display it somewhere else bigger.)

2)

Also when the user clicks on a row in the grid.. I want a js function to be called and the data from the row to be passed into the function?

A: 

I figured out 2 of 3

To listen for clicks:

myfirstgrid.php

$selectorder = <<<ORDER
function(rowid, selected) 
{ 
    if(rowid != null) { 
        alert("selected: "+rowid); 
    } 
} 
ORDER;
$grid->setGridEvent('onSelectRow', $selectorder);

To update the SelectCommand

Make your page that sets it, listen for GET vars to build it from.

Then on your page you can change it with js like this:

main page

function changeSelectCommand(){
    $('#grid').setGridParam({url:'myfirstgrid.php?brand=stardust'}); 
    $('#grid').trigger("reloadGrid");  
};

myfirstgrid.php

....
$brand = $_GET['brand'] ? $_GET['brand'] : "nike"];
$grid->SelectCommand = 'SELECT product_id, product_name, product_brand, product_price FROM cart_product WHERE product_brand = "'.$brand.'"';
....

I still havent figured out how to get number of results?

John Isaacks