spring 通过jquery的dategrid搜索条件给输入框修改。

原创
2013/03/15 12:32
阅读数 58

js上:

 function searchSupplier(){
       $('#searchSupplier').window('open');
   }
   function searchSupplierSubmit() {
       var name = $('#searchSupplier #supplier_name').val();
       alert(name);
       $('#tt-supplier').datagrid({
           url: encodeURI('${pageContext.request.contextPath}/searchSupplier?supplierName='+name),
           title: '供应商',
           width: 670,
           height: 'auto',
           fitColumns: true,
           rownumbers: true,
           singleSelect: true,
           columns: [[
                   {field: 'id', title: 'id', width: 30},
                   {field: 'supplierNo', title: '编号', width: 50},
                   {field: 'supplierName', title: '供应商名称', width: 200},
                   {field: 'bussiness', title: '业务', width: 200},
                   {field: 'contact', title: '联系人', width: 100},
                   {field: 'do', title: '操作', width: 50, align: 'left'}
               ]]
       });
   }
   function searchSuplierSelected(id,name) {
  alert(name);
       $("#procureplan_supplier").val(name);
       $("#supplier").val(id);
       $("#searchSupplier").window('close');
   }
jsp这么写的:

<td class="label" valign="top">
<fmt:message key="procureplan.supplier.title"/>:
</td>
<td>
<input  id="procureplan_supplier"  required="true" style="width:280px" readonly="true"/>
                        <form:hidden id="supplier" path="supplier.id"/>
                        <a href="javascript:void(0)" onclick="searchSupplier()"><img src="${pageContext.request.contextPath}/images/icons/view.gif"  border="0" style="margin-top:2px;" ></a>
</td>
<!--搜索供应商-->
<div id="searchSupplier" class="easyui-window" title="搜索供应商" closed="true" iconCls="icon-add" style="width:710px;height:400px">
    <table width="100%">
        <tr>
            <td width="14%"><fmt:message key="procureplan.supplier.title"/></td>
            <td width="16%"><input id="supplier_name" type="text" style="width: 100px"></td>
            <td width="10%"></td>
            <td width="29%"><input type="submit"onclick="searchSupplierSubmit()"  value="确定"border="0" style="margin-top:1px"></td>
        </tr>
    </table>
    <table id="tt-supplier" align="center"></table>
</div>
后台control是这么写的:

/*
* 根据供应商名称查找供应商转换成json数据
* @RequestParam supplierName
*/
//2013-01-08------------------------------------------------------------------------------
@RequestMapping("/searchSupplier")
public @ResponseBody Map<String,List> searchSupplier(String supplierName)throws Exception{
Map<String,List> josnMap = new HashMap<String,List>();
String tempStr=supplierName;//将supplierName赋值给tempStr;
String result=new String(tempStr.getBytes("ISO-8859-1"),"UTF-8");//转成utf-8;
List<Supplier> suppliers = systemManageService.findAllSuppliersByName(result);
List list=new ArrayList();
if(suppliers.size()>0){
for(Supplier supplier:suppliers)
{
Map<String,Object> supplierMap=new HashMap<String,Object>();
int id=supplier.getId();
String name=supplier.getSupplierName();
supplierMap.put("id", supplier.getId());
supplierMap.put("supplierNo", supplier.getSupplierNo());
supplierMap.put("supplierName", supplier.getSupplierName());
supplierMap.put("bussiness", supplier.getBussiness());
supplierMap.put("contact", supplier.getContact());
supplierMap.put("do", "<a href='#' onclick='searchSuplierSelected(\""+id+"\", \""+name +"\")'>选择</a>");
list.add(supplierMap);
}
}
else{
Map<String,Object> supplierMap=new HashMap<String,Object>();
supplierMap.put("id", null);
supplierMap.put("supplierNo", null);
supplierMap.put("supplierName", null);
supplierMap.put("bussiness", null);
supplierMap.put("contact", null);
list.add(supplierMap);
}
josnMap.put("rows",list);
return josnMap;
}

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部