I've been playing around with jqGrid but cant work out how to implement the search functionality. Ideally I'd like to use the 'Advanced Search' - I imagine that when the user submits the advanced search form, the entered data is fired to the url specificed under 'editurl'? Im gu开发者_运维问答essing this URL then outputs the resultset filtered using the search criteria.
My question is how is this actually done? Am I right in the URL data is sent to, and if so how can this data be accessed? Im fairly decent at jQuery, and good at Javascript- Im using PHP for all server side stuff (expert knowledge, and of mySQL) but cant for the life of me seem to work this out...at present my Java is:var lastsel;
$("#list").jqGrid({
url:'example.php',
datatype: 'xml',
hidegrid: false,
mtype: 'GET',
colNames:['id','ti', 'na','al','de'],
colModel :[
{name:'id', index:'id', width:55, hidden:true, key:true, resizable:true},
{name:'ti', index:'ti', width:75, resizable:true,editable:true},
{name:'na', index:'na', width:200, align:'left', resizable:true,editable:true},
{name:'al', index:'al', width:200, align:'left', resizable:true,editable:true},
{name:'de', index:'de', width:400, align:'left', sortable:false, resizable:true,editable:true}
],
pager: '#pager',
height:'100%',
rowNum:10,
searchGrid: {multipleSearch:true, caption : 'go'},
rowList:[50,100,200],
sortname: 'ticker',
sortorder: 'asc',
viewrecords: true,
editurl:'example.php',
multipleSearch:true,
caption: 'Definitions'
});
All help much appreciated!i dont know if you found your answer anywhere, but i just did it and i can help you a little.
They pass a parameter called filters. Is a json...you have to receive it as a request and transform it in an array.
I work with php, so i used a function called json_decode($yourvar, true). It transformed the filter in an array. The array is easier to manipulate.
As you said the URL contains the search information.
But the search isn't make in the client side, you have to implement it in your server side.
And the code you posted isn't Java, is JavaScript.
I'm just trying to learn this myself, but I'd recommend checking out their PHP search demo at: http://www.trirand.com/blog/jqgrid/jqgrid.html
On the left hand side, open the accordion tab and go down to Live Data Manipulation, then click "Searching Data". You'll see the live example along with code. This particular example uses XML instead of JSON.
In their example, I don't understand how they pass the search variables to the php code: it just happens. If it was json, I know it would be in the URL.
In any case, I can see that the data is returned to the HTML page in the same manner as a normal grid populate method: it's returned to jqGrid using an XML format, and jqGrid knows how to take data in that format and run with it.
Hope that helps.
精彩评论