The
jquery Easyui Package
uses the Easyui DataGrid section, primarily to save writing a bunch of HTML code.
through encapsulation, you can save every page to write a bunch of Easyui code, relatively simple, personal feel, after all, is to do their own, it is inevitable that the ego feel better, haha. After the
is encapsulated, simply refer to the various needs libraries in HTML and write <table id= "myID" ><table> in the body,
and then call Basegrid in JS (' myID ', " Focus_ft "," <{:u (' focus/focuslist ')}> ", cols,data_opt); Can.
The first parameter in the method, the table ID, and the second parameter of the
is the ID of the div where the filter function needs to be added, such as the area of the red box
The third parameter is the address that loads the data, can be a routing path, or other data address such as static file address, example of the URI is the thinkphp routing address
The fourth parameter, is the column configuration, how many columns, configure how many, on the copy paste of the live, should be quite relaxed. See
The fifth parameter is the configuration that needs to be changed, the specific configuration item reference Easyui Official document, can omit, will load by default.
So all you have to do is what's in the box below (note,
Formatter:orderoperateformatter What is this thing?)
Orderoperateformatter This is a JS method, write yourself, each page is different. such as editing, deletion and so on.
Other columns can be written if necessary, this is the Easyui property
$ (function () { var data_opt = {
' pagelist ': [5,10, 20, 30,50], ' pageSize ': 10, "Sortname": "id",
"SortOrder": "Desc" }; var cols = [[ //Note to two nested brackets { field: ' ck ', checkbox:true }, { field: ' id ', title: ' dan ', width: 60, align: ' center ', sortable: TRUE&NBSP}, { field: ' Name ', title: ' recommended bit name ', width: 80, align: ' Center '}, { field: ' m ', title: ' management operations ', width: 80, align: ' center ', formatter:orderoperateformatter } ]];
basegrid (' DG ', "focus_ft", "<{:u (' focus/focuslist ')}>", cols);
}); Function orderoperateformatter (val) { var btn = [];
btn.push (' <a id= "Btedit" href= "__url__/modify/id/' +val+ '" > Edit </a> ');
btn.push (' <a id= "Btdel" href= "#" > Delete </a> ");
return btn.join ("|"); }
&NBSP
is the page section, and the encapsulated complete code.
Page section:
<body> <div class= "Right-page" > <form id= "SubmitForm" name= "SubmitForm" action= "" method= "post" > <div class= "Order-search" > <span> <input type= "hidden" name= "IDs" > <input id= "RoleBt70" type= " Button " class=" Order-search-button " onclick=" Alldel () " value=" Delete all "/> <input id= "RoleBt71 " type=" button " class=" Order-search-button " onclick=" Alldisplay () " value=" Show All "/ > <input id= "roleBt72" type= "button" class= "Order-search-button" Onclick= "Allhidden ()" value= "all hidden"/> </span> </div> </form> <div class= "Order-list" > <div class= "Order-list-table" > <table id= "DG" title= "recommended Bit" style= "width:80%; height:650px " > </ Table> </div> </div> <div Id= "focus_ft" class= "Order-search" > <form> <span> <select name= "Search[type]" id= "Order_select_one" > <option value= "id" > Dan number </option> <option Value= "Name" > name </option> </select> </span> <span> <input name= "Search[txt_ Value] " type=" text " size=" /> </span> <span> Release Date: <input type= "text" size= " " Name= "Search[date_from]" " class=" Wdate " onfocus=" Wdatepicker ({datefmt: ' yyyy-MM-dd HH:mm: SS '}] " />-<input type=" text " size=" name= "search[date_to" class= "Wdate" onfocus= "Wdatepicker ({datefmt: ' Yyyy-mm-dd hh:mm:ss '})"/> </span> <input type= "button" id= " RoleBt1 " value=" Check inquire " class=" Order-search-button " onclick=" Search (' DG ', this); " /> </form> </div> <br/ > </div> </body>
encapsulates the JS code:
/*version 1.0 &NBSP;*MJ *//** Click to list the expanded content of the row, using this method * id:grid ID * dg_
Toolbar:grid complex operation part ID, "dg_area_id" * url: Get Data Url address,--"<{:u (' focus/focuslist ')}>"--"A.json" * expandurl: Hide content URL address * cols: column information var cols = [[ //Note two nested brackets { field: ' id ', title: ' dan ', width: 60, align: ' center ', sortable: &NBSP;TRUE&NBSP}, { field: ' name ', title: ' recommended bit name ', width: 80, align: ' Center '}, { field: ' m ', title: ' management operations ', width: 80, align: ' Center ', formatter: orderoperateformatter }
]]; * data_opt:grid property, can omit var data_opt = { ' pagelist ': [10, 20, &NBSP;30,50], ' pageSize ':
}; */Function expandgrid (id,dg_toolbar,mainurl,expandurl,cols,data_opt) { var default_opt = { ' border ': False, ' fit ': true, ' Fitcolumns ': true, ' roWnumbers ': True, ' Singleselect ': false, ' Checkonselect ': false, ' Selectoncheck ': True, ' pagination ': true, ' pagelist ': [10, 20, 30, 50], '
PageSize ': }; for (opt in data_opt) { default
_OPT[OPT]=DATA_OPT[OPT]; &NBSP;&NBSP;&NBSP;&NBSP} $ (' # ' +id). DataGrid ({
url: mainurl, loadMsg: ' data loading, please wait ... ', pagesize: default_opt["PageSize"], pagelist: default_opt["PageList"], pagination:default_opt["pagination"], singleselect:default_opt["Singleselect"], fitcolumns:default_opt["Fitcolumns"], checkonselect :d efault_opt["Checkonselect"], selectoncheck:default_opt[" Selectoncheck "], view: detailview, toolbar: dg_toolbar== ""? "": "#" +dg_toolbar,
columns:cols, detailformatter:function (index,row) { return ' <div class= ' DDV '
style= "Padding:5px 0" ></div>; }, &NBSP;&NBSP;&NBSP;&NBSP;&NBsp; onexpandrow: function (index,row) {
var ddv = $ (This). DataGrid (' Getrowdetail ', index). Find (' DIV.DDV '); ddv.panel ({ height: "Auto", border:false, cache:false, href:expandurl+row.id, onload:function () { $ (' # ' +id). DataGrid(' Fixdetailrowheight ', index); }
}); $ (' # ' +id). DataGrid ('
Fixdetailrowheight ', index);
} }); /** General grid display * id:grid ID * dg_toolbar:grid complex operations Section ID, "dg_area_id" * url: Get Data URL address,--"<{:u (' focus/focuslist ')}>"--"A.json" * cols: Column information var cols = [[ Note two nested brackets { field: ' id ', title: ' Dan Hao ', width: 60, align: ' Center ', sortable: true }, &nbsP { field: ' name ', title: ' recommended bit name ', width: 80, align: ' center '}, { field: ' m ', title: ' management operations ', width: 80, align: ' center ', formatter:o rderoperateformatter }
]]; * data_opt:grid property, can omit var data_opt = { ' pagelist ': [10, 20, &NBSP;30,50], ' pageSize ':
}; */Function basegrid (id,dg_toolbar,url,cols,data_opt) { var default_opt = { ' border ': false, ' fit ': true, ' Fitcolumns ': True, ' rownumbers ': true, ' Singleselect ': false, ' Checkonselect ': False, ' Selectoncheck ': true, ' pagination ': true, ' pagelist ': [5, 10, &NBSP;20,&NBSP;30,&NBSP;50], ' pageSize ':
}; for (opt in data_opt) { default
_OPT[OPT]=DATA_OPT[OPT]; &NBSP;&NBSP;&NBSP;&NBSP} $ (' # ' +id). DataGrid ({ &nbsP; url: url, loadMsg: ' data loading, please wait ... ' , pagesize: default_opt["PageSize"], pagelist: default_opt["PageList"], pagination:default_opt["pagination"], singleselect: default_opt["Singleselect"], fitcolumns:default_opt["FitColumns "], checkonselect:default_opt[" Checkonselect "], selectoncheck:default_opt["Selectoncheck"], toolbar: dg_toolbar== ""? "": "#" +dg_toolbar,
columns:cols }); } function contains (ARR,&NBsp;obj) { for (var i = 0; i < arr.length;
i++) { if (arr[i] === obj) {
return true; } return
False /* Get the ID string of the grid, separated, if it is a string, then "," to separate the *grid_id grid ID *id the field to be assembled id * * function getselections (grid_id,id) { var rows = $ ("#" +grid_id). DataGrid ('
Getselections ');
var ss=[]; for (var i=0; i<rows.length; i++) {
var row = rows[i]; ss.push (eval ("row.")
+id)); } return sS.join (', ');
}/* * Query method, the query area must be covered with <form></form>, easy to submit server processing * incoming grid id,that Express Query button, incoming this can */Function search (grid_id,that) { var data = $ ("#" +grid_
ID);
var queryparams = data.datagrid (' Options '). Queryparams; $.each ($ (that). Parent (' form '). Serializearray (), function (
{ queryparams[this[' name ']] = this[' value '];
});
data.datagrid ({ pagenumber: 1
}); }
Jquery Easyui Encapsulation Simplify operations
confirm function confirm (Msg, control) { $.messager.confirm (' confirmation ',
msg, function (R) { if (R) {
eval (Control.toString (). Slice (11));
} });
return false; }//load function load () { $ ("<div class=\" Datagrid-mask\ "></div") > "). css ({ display: " block ", width: " 100% ", height: $ (window). Height () })
. Appendto ("body"); $ ("<div class=\" datagrid-mask-msg\ "></div>"). HTML ("Running, please wait ..."). "). Appendto (" Body "). CSS ({ display: " block ", left: ($ (document.body). Outerwidth (True) - 190) / 2, top: ($ (window). Height () - 45) / 2 });
}//display load function dispalyload () { $ (". Datagrid-mask"). Remove ();
$ (". Datagrid-mask-msg"). Remove (); //Pop-up Alert box alert function showmsg (Title, msg, isalert) { if ( Isalert !== undefined && isalert) {
$.messager.alert (TITLE,&NBSP;MSG);
} else { $.messager.show ({ title: title, msg: msg,
showType: ' Show ' }; &NBSP;&NBSP;&NBSP;&NBSP}}//delete confirmation confirm function deleteconfirm () { return showconfirm (' Warm hints ', ' Are you sure you want to delete it? '); //Pop-up Confirmation box confirm Function showconfirm (title, msg, callback) { $. Messager.confirm (title, msg, function (r) { if (R) { if ( Jquery.isfunction (callback))
callback.call ();
} }); }//progress bar function showprocess (isshow, title, msg) { if (!isshow) { $.messager.progress (' close ');
return; &NBSP;&NBSP;&NBSP;&NBSP} var win = $.messager.progress ({ title: title, msg: msg }); }//Pop-up box window Function showmywindow (title, href, width, height, modal, minimizable, maximizable) { $ (' #myWindow '). Window ({ title: title, width: width === undefined ? 600 : width, Height: height === undefined ? 400 : height, content: ' <iframe scrolling= ' yes ' frameborder= ' 0 " src=" ' + href + ' " style=" width:100%;height:98%; " ></iframe> ', // href: href === undefined ? null : href, modal: modal === undefined ? true : modal, minimizable: minimizable === undefined ? false : minimizable, maximizable: maximizable == = undefined ? false : maximizable, Shadow: false, cache: false, closed: false, collapsible: False, resizable: false,
loadingMessage: ' Loading data, please wait a moment ... ' }; ///Turn off pop-up frame window Function closemywindow () { $ (' #myWindow '). Window (' Close '
); /** * Empty the contents of the specified form, the parameter is the ID * Note of the target form: When you enter new content using Jquery easyui pop-up windows, each time you open must empty the last entered history data, the usual approach is to empty each input component: $ ("#name"). Val (""), do it, *
When the input component is very cumbersome, the resulting JS code is very long, then you can put all the input components into the form form *, and then call the following methods. * * @param formid ID/function resetcontent (formid) { var of form forms that will empty content
clearform = document.getelementbyid (Formid); if (null != clearform && typeof (ClearForm) != "undefined") { clearform.reset () &NBSP;&NBSP;&NBSP}/** * Refresh DataGrid list (for DataGrid in Jquery easy ui) * Note: This method is recommended to refresh DataGrid list data (i.e. reload data) , it is not recommended to use the statement *$ (' #dataTableId ') directly. DataGrid (' reload '); To refresh the list data, because the latter, if you want to modify the project at all times in the system to do some other action,
So you're going to have to modify all the code in the system that involves refreshing *, which is a lot of work and is easy to omit, but if you use this method to refresh the list, then the requirement for this fix will be easy to do without error or omission. * * @paramdataTableId the DataGrid-dependent table list ID/function flashtable (datatableid) {that will refresh the data $ (' # ' + datatableid). DatagrID (' reload '); /** * Cancel row selection in DataGrid (for DataGrid in Jquery easy ui) * Note: You have resolved the option of not canceling the Select all checkbox, but only if you must show the list *
The table on which the data DataGrid relies is placed in the most comprehensive HTML document, with at least no * other checkbox components before the table. * * @paramdataTableId the target table list ID of the selected data record will be canceled/Function clearselect (Datatableid) {
$ (' # ' + datatableid). DataGrid (' Clearselections '); //Deselect All selected $ ("input[type= ' checkbox ')" in the DataGrid. EQ (0). attr ("
Checked ", false); /** * Closes the Jquery easyui pop-up window (for jquery easy ui) * * @paramdialogId the ID of the window to be closed/function Closedialog (dialogID) { $ (' # ' + dialogid). Dialog (' Close ');/** * Adaptive table width processing (applicable to the column width of the datagrid in Jquery easy ui), * Note: You can implement the column widths of the list to change with the width of the browsing, that is, to set the DataGrid *
The column widths can be scaled in different resolution browsers to meet the requirements of different resolution browsers * use methods: (for example: {field: ' Ymname ', title: ' Number ', width:fillsize (0.08), align: ' center '},) * * @parampercent The percentage of the width of the entire window (in decimal form, such as 0.3 for 30%) * @return The width of the column to be calculated by the current window and corresponding percentages * * funcTion fillsize (percent) { var bodyWidth =
Document.body.clientWidth;
return (bodywidth - 90) * percent; /** * Gets the ID of the table in the DataGrid list where the selected record line (radio) * * @paramdataTableId the target record * @paramerrorMessage
If you do not select a row (that is, no multiple rows are selected or selected) * @return The selected Row object, if the return value is NULL, or "null" (sometimes the browser converts null to the string "null") indicates that there is no * to select a row of records. * * Function getsingleselectrow (datatableid, errormessage) { var rows
= $ (' # ' + datatableid). DataGrid (' Getselections ');
var num = rows.length; if (num == 1) {
return rows[0]; } else { $.messager.alert ('
Prompt message ', errormessage, ' info '); return null; &NBSP;&NBSP;&NBSP;&NBSP}/** * gets the ID of the selected record in the DataGrid, with multiple IDs separated by commas * Note: This method uses the premise that the IDfield property of the DataGrid corresponds to the field name in the list JSON data must be ID * @paramdataTableId the ID of the DataGrid list table where the target record is located * * @
return the ID string of the selected record (multiple IDs separated by commas) * * Function getselectids (datatableid, nooneselectmessage) {
var rows = $ (' # ' + datatableid). DataGrid (' GetSelections ');
var num = rows.length;
var ids = null; if (num < 1) { if (null != nooneselectmessage) $.messager.alert (' Hint message ', nooneselectmessage, ')
Info ');
return null; } else { for (var i = 0; i < num; i++) { if (null == ids | | i == 0) {
ids = rows[i].id; } else { ids = ids +
"," + rows[i].id; }
} return ids; &NBSP;&NBSP;&NBSP;&NBSP}/** * Delete Selected records (for DataGrid in Jquery easy ui) (deleted by field is ID) * Note: This method automatically converts the ID of the selected record ( The IDfield property of the DataGrid corresponds to the field name in the list JSON data must be ID) * Dynamically assembled into a string, multiple IDs separated by commas (e.g., 1,2,3,8,10), and then stored in the variable IDs for incoming background, background *
You can use this parameter name to get all the ID value strings from the Request object, which is handy when assembling SQL or HQL statements with the in * keyword. * In addition, the background code must be in the form of Ajax after the operation to return JSOn format prompts, the JSON format information in the hint must have a *message field that holds the user's information for some prompts such as success and failure of this deletion operation. * * @paramdataTableId The ID * of the list table where the record will be deleted @paramrequestURL interact with the background server, request path for specific deletions * @paramconfirmMessage Delete Confirmation * * Function deletenotebyid (datatableid, requesturl, confirmmessage) { if (null == confirmmessage | | typeof (confirmmessage) == "Undefined" | | "" == confirmmessage) { confirmmessage
= "OK to delete selected records?"; &NBSP;&NBSP;&NBSP;&NBSP} var rows = $ (' # ' + datatableid).
DataGrid (' Getselections ');
var num = rows.length;
var ids = null; if (num < 1) { $
. Messager.alert (' Hint message ', ' Please select the record you want to delete! ', ' info '); } else { $.messager.confirm (' Confirm ', confirmmessage, function (R) { if (R) { for (var i = 0; i < num; i++) { if (null = = ids | | i == 0) {
ids = rows[i].id; } else { ids = ids + "," + rows[i].id;
} } $.getjson ( requesturl, { "IDs": ids }, function (data) { if (null ! = data && null != data.message && "" != Data.message) { $.messager.alert (' Hint message ', data.message, ' info ')
;
flashtable (Datatableid); } else { $.messager.alert (' Hint message ', ' delete failed!)
', ' warning '); }
clearselect (Datatableid);
}); }
}); }
}
easyui window plug-ins in the secondary package for easy Operation
Plug-in code:
$.fn.hwindow = function (options) { var defaults = { width: 500, //width height: 400 , //height iconCls: ', // Icon Class collapsible: false, //Folding minimizable: false, //min maximizable: false, //Maximum Resizable: false, //change the window size title : ' window title ', //window title modal: true, //modal submit: function () { alert (' Write code to execute.
'); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}, html: ' '  } var options = $.
Extend (defaults,options);
var html = options.html; $ (' #w '). Window ({title:options.title,width:options.width,height:options.height,content: Buildwindowcontent (html,options.submit), collapsible:options.collapsible,minimizable:options.minimizable,maximizable:o
Ptions.maximizable, modal:options.modal,iconcls:options.iconcls
&NBSP;&NBSP;&NBSP;&NBSP}). Window (' open '); function buildwindowcontent (CONTENTHTML,FN) { var centerDIV = $ (' <div region= ' Center " border=" false " style=" PADDING:5PX; "
></div> '). HTML (contenthtml); $ (' <div class= "Easyui-layout" fit= "true" ></ Div> ') .append (centerdiv) .append (' <div region= "South" border= "false" style= "Padding-top:5px;height : 40px; overflow:hidden; text-align:center;background: #fafafa; BordeR-top: #eee 1px solid; " > <a iconcls= "Icon-ok" > OK </a><a iconcls= "Icon-cancel" > Cancel </a> </div> ') .appendto ($ (' #w '). Empty ())
.layout ();
$ ('. easyui-layout a[iconcls] '). LinkButton (); $ (' a[iconcls= "Icon-cancel"]). Click (function () {
$ (' #w '). Window (' close ');
});
$ (' a[iconcls= "Icon-ok"]). Unbind (' click '). Click (FN); &NBSP;&NBSP;&NBSP;&NBSP}}
The above code can be saved to a JS file, easy to use in the future can be introduced directly, I in the example to save this code as Jquery-easyui-window-expand.js
CSS and JS files need to be introduced:
<link rel= "stylesheet" type= text/css "href=". /themes/default/easyui.css ">
<link rel=" stylesheet "type=" Text/css "href=". /themes/icon.css ">
<script type=" Text/javascript "src=". /jquery-1.4.2.min.js "></script>
<script type=" Text/javascript "src=". /jquery.easyui.min.js "></script>
<script type=" Text/javascript "src=" Jquery-easyui-window-expand.js "></script>
Html:
<input type= "button" value= "New Window" id= "Btnopen" >
<input type= "button" value= "new Window 1" id= "BtnOpen1" >
<input type= "button" value= "New Window 2" id= "BtnOpen2" >
<!--for pop-up windows div--> <div id=
"W" ></div >
JS Call:
$ (' #w '). Hwindow ();
Complete code:
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "http:// Www.w3.org/TR/html4/loose.dtd "> <html> <head> <title> New document </title> <meta name= "generator" content= "EditPlus" > <meta name= "Author" content= "Crazy Scholar" > <meta name= "Keywords" content= "" > <meta name= "Description" content= "> <link rel=" stylesheet " type=" Text/css " href=". /themes/default/easyui.css "> <link rel=" stylesheet " type=" Text/css " href=". /themes/icon.css "> <script type=" Text/javascript " src=". /jquery-1.4.2.min.js "></script> <script type=" Text/javascript " src=". /jquery.easyui.min.js "></script> <script type=" Text/javascript " src=" Jquery-easyui-window-expand.js "></script> <script type=" TeXt/javascript ' > $ (function () { $ (' # Btnopen '). Click (function () { var
html = ' <input type= ' text " id=" Text1 " name=" ">";
var fn = function () { alert ($ (' #
Text1 '). Val ()); }
$ (' #w '). Hwindow ({HTML:HTML,SUBMIT:FN});
}); $ (' #btnOpen1 '). Click (function () { var html = ' <input type= ' text " id=" Text1 " name=""><input id=" BTN1 " type=" button " value=" submitted " onclick=" ">";
var fn = function () { alert (' second window ')
; }
$ (' #w '). Hwindow ({html:html,title: ' second window ', SUBMIT:FN}); $ (' #btn1 '). Click (function () { alert ($ (this). Prev ()
. val ());
});
}); $ (' #btnOpen2 '). Click (function () { var html = ' <textarea name= ' " rows=" " cols=" "></textarea
><input type= "checkbox" name= "" > ";
var fn = function () { alert (' third window ')
; }
$ (' #w '). Hwindow ({iconcls: ' Icon-save ', Html:html,title: ' Third window ', SUBMIT:FN});
}); &NBSP;&NBSP;&NBSP;&NBSP}) </script> </head> <body> <input type= " Button " value=" New Window " id=" Btnopen " > <input type=" button " value=" new Window 1 " id=" BtnOpen1 " > <input type=" button " value=" New Window 2 " id=" BtnOpen2 " > < Div id= "W" ></div> </body> </html>