Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css" />
  2. <link href="http://www.trirand.net/aspnetmvc/Content/themes/ui.jqgrid.css" rel="stylesheet" type="text/css" />
  3. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/JavaScript"></script>
  4. <script src="http://www.trirand.net/aspnetmvc/Scripts/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
  5. <script src="http://www.trirand.net/aspnetmvc/Scripts/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
  6.  
  7. <script type="text/javascript">
  8. var gridData;
  9. var obj;
  10.  
  11. function search(jsonString) {
  12. $("#pdata").jqGrid("GridUnload");
  13.  
  14. gridData = JSON.stringify(jsonString);
  15. obj = JSON.parse(gridData);
  16.  
  17. jQuery("#pdata").jqGrid({
  18. data&colon; jsonString,
  19. datatype: 'local',
  20. colNames:['Id','Name'],
  21. colModel:[
  22. {name:'Id',index:'Id', width:40},
  23. {name:'Name',index:'Name', width:40}],
  24. rowNum:10,
  25. rowList:[5,10,20,30,50,100, 1000],
  26. pager: '#ppdata',
  27. sortname: 'name',
  28. viewrecords: true,
  29. sortorder: "desc",
  30. caption:"Contact Data",
  31. width: 800,
  32. height: 180,
  33. });
  34. $("#pdata").trigger("reloadGrid");
  35. }
  36.  
  37. function showDataInJqGrid(){
  38. var accName = document.getElementById("query").value;
  39. contactSearch(accName);
  40. }
  41.  
  42. function contactSearch(name) {
  43. var jsonString;
  44. Visualforce.remoting.Manager.invokeAction(
  45. '{!$RemoteAction.GridController.showContacts}',
  46. name,
  47. function (result, event) {
  48. if(event.type == 'exception'){
  49. alert(event.message);
  50. } else{
  51. jsonString = result;
  52. search(jsonString);
  53. gridData = JSON.stringify(jsonString);
  54. }
  55. },
  56. {escape: true}
  57. );
  58.  
  59. // I first tried this below option also to call controller method but same results i got
  60. /*GridController.showContacts(name, function (result, event) {
  61. if(event.type == 'exception'){
  62. alert(event.message);
  63. } else{
  64. jsonString = result;
  65. search(jsonString);
  66. gridData = JSON.stringify(jsonString);
  67. }
  68. }); */
  69. }
  70.  
  71. </script>
  72.  
  73. <apex:sectionHeader title="Contact Search using AccountID" subtitle="Search Contact" />
  74. <apex:pageBlock mode="maindetail">
  75. <apex:form id="qform" >
  76. <apex:pageBlockSection title="Search Contact for the Account" collapsible="false" columns="1" >
  77. <table width="100%">
  78. <tr>
  79. <td><h3>Enter Account Name </h3>&nbsp;&nbsp;<input type="text" id="query" />&nbsp;&nbsp;&nbsp;
  80. <input type="button" value="Show Contacts " class="btn" onclick="showDataInJqGrid();" />&nbsp;&nbsp;&nbsp;
  81. </td>
  82. </tr>
  83. </table>
  84. </apex:pageBlocksection>
  85. </apex:form>
  86.  
  87. <apex:pageBlockSection title="Contacts in Response" collapsible="false" rendered="true">
  88. <div id="response" style="font-size: 16px;width: 300px;font-family: monospace; font-stretch: expanded" />
  89. <table id="pdata"></table>
  90. <div id="ppdata"></div>
  91. </apex:pageBlocksection>
  92. </apex:pageblock>
  93. </apex:page>
  94.  
  95. global class GridController {
  96.  
  97. public GridController() {
  98.  
  99. }
  100.  
  101. @RemoteAction
  102. global static List<Contact> showContacts(String accName){
  103. system.debug('inside method: '+accName);
  104. accName = '%'+ accName+'%';
  105. List<Contact> lst_contacts = new List<Contact>([select id, name from contact where Account.Name LIKE : accName]);
  106. return lst_contacts;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement