Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Friday, 18 March 2011

Displaying JQGrid with default search condition

Being using JQGrid for sometime, have at one point required to display data in jqgrid but with a default search condition.

Its as simple as just passing data using the parameter serializeGridData in jqgrid

$(function () {

 var defaultsearchField = "id";
 var defaultsearchString = "5";
 var defaultsearchOper = "gt";



 jQuery("#grid").jqGrid({    
  url:'GetDetails.asmx?team=All',    
  datatype: "json",    
  colNames:['ID','Name','Country','Progress'],    
  colModel:[    
  {name:'id',index:'id', width:55},    
  {name:'Icon',index:'Icon', width:90},    
  {name:'name',index:'name asc, invdate', width:100},    
  {name:'designation',index:'designation', width:80}],    
  rowNum:10,    
  rowList:[10,20,30],    
  pager: '#pager',    
  sortname: 'id',    
  viewrecords: true,    
  sortorder: "desc",    
  caption:"JSON Data",
  serializeGridData: function (postData) {

  if(defaultsearchField != null)
  {
   postData.searchField = defaultsearchField; 
   postData.searchString = defaultsearchString; 
   postData.searchOper = defaultsearchOper;
  }
  else
  { 
   if (postData.searchField === undefined) postData.searchField = null;
   if (postData.searchString === undefined) postData.searchString = null;
   if (postData.searchOper === undefined) postData.searchOper = null; 
  }
  return JSON.stringify(postData);
  },
 });   

});

Now the webservice will get the default search condition and should be able to work straight away. Unless if search is not handled on web service side.

Three things are certain:
Death, taxes, and lost data.
Guess which has occurred.
~David Dixon, 1998, winning entry of the Haiku Error Messages 21st Challenge by Charlie Varon and Jim Rosenau, sponsored by Salon.com

1 comments:

Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers