Implementation of easyUI searchBox search box

Source: Internet
Author: User

Easyui searchBox search box

<Body class = "easyui-layout" data-options = "fit: true"> <div data-options = "region: 'center', border: false "style =" overflow: hidden; "> <table id =" datagrid "> </table> </div> <div id =" search "style =" display: inline; padding-top: 10px; "> <! -- Here, padding-top is used to align the search column down, that is, with the "add" button, but it is not useful in HTML, test availability on the jsp page --> <input id = "searchBox" class = "easyui-searchbox" searcher = "searchData" prompt = "Enter the query content" style = "width: 300px "> </input> <div id =" searchMenu "style =" width: 100px "> </div> <div id =" menu "class =" easyui-menu "style =" width: 120px; display: none; "> <div onclick =" append (); "data-options =" iconCls: 'icon-add' "> add </div> <div onclick =" removeData (); "data-options =" iconCls: 'icon-delete' "> Delete </div> <div onclick =" edit (); "data-options =" iconCls: 'icon-edit' "> edit </div> </body>

2. js

// Generate the search drop-down list var fields =$ ('# datagrid') for the loop column name '). datagrid ('getcolumnfields '); var muit = ""; for (var I = 0; I <fields. length; I ++) {var opts =$ ('# datagrid '). datagrid ('getcolumnoption ', fields [I]); muit + = "<div name ='" + fields [I] + "'>" + opts. title + "</div>" too many characters ('{searchmenu'{.html({('{searchmenu'{.html () + muit); $ ('# searchbox '). searchbox ({menu: '# searchMenu'}); // obtain the generated search box var tSearch =$ ("# search "); // Add the generated search box to the toolbar $ (". datagrid-toolbar "). append (tSearch );

3. search methods

function searchData(value,name){ $('#datagrid').datagrid('load', { "searchKey": name, "searchValue": value });}


4. searchKey is the field name to be queried, and searchValue is the value of this field name. The background receives these two parameters and concatenates them into an SQL query.

A. This is the total query record.

String hql = "select count(*) from PageImg p where 1=1";if (!UtilTool.isNull(pageImgModel.getSearchKey()) && !UtilTool.isNull(pageImgModel.getSearchValue())) {hql = hql + " and p." + pageImgModel.getSearchKey() + " like '%" + pageImgModel.getSearchValue() + "%'";}
B. This is the query list.

private List<PageImg> find(PageImgModel pageImgModel) {String hql = "from PageImg p where 1=1 ";List<Object> values = new ArrayList<Object>();hql = addWhere(pageImgModel, hql, values);if (pageImgModel.getSort() != null && pageImgModel.getOrder() != null) {hql += " order by " + pageImgModel.getSort() + " " + pageImgModel.getOrder();}return pageImgDAO.find(hql, values, pageImgModel.getPage(), pageImgModel.getRows());}private String addWhere(PageImgModel imgModel, String hql, List<Object> values) {if (!UtilTool.isNull(imgModel.getSearchKey()) && !UtilTool.isNull(imgModel.getSearchValue())) {hql += "and p." + imgModel.getSearchKey() + " like ? ";values.add("%" + imgModel.getSearchValue().trim() + "%");}return hql;}

Encapsulated DAO

/*** Query set (with pagination) ** @ param hql * @ param page * @ param rows * @ return */public List <T> find (String hql, List <Object> param, integer page, Integer rows); public List <T> find (String hql, List <Object> param, Integer page, Integer rows) {if (page = null | page <1) {page = 1 ;}if (rows = null | rows <1) {rows = 10 ;} query q = this. getCurrentSession (). createQuery (hql); if (param! = Null & param. size ()> 0) {for (int I = 0; I <param. size (); I ++) {q. setParameter (I, param. get (I) ;}} return q. setFirstResult (page-1) * rows ). setMaxResults (rows ). list ();}

One: (found which padding is set still cannot align the search box with the button)








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.