/*** Clear the content in the specified form and set the parameter to the id of the target form * Note: When you use the JqueryEasyUI pop-up window to input new content, each time the previous input history * data is opened, the common method is to empty each input component: $ (# name ). val (). In this way, * when many input components exist
/**
* Clears the content of the specified form. The parameter is the id of the target form.
* Note: When you use the Jquery EasyUI pop-up window to input new content, you must clear the previous input history each time you open it.
* Data. In this case, the common method is to empty each input component: $ ("# name"). val,
* When many input components are involved, the JavaScript code is generated for a long time. In this case, all input components can be put into a form.
*, And then call the following method.
*
* @ Param formId: id of the form to be cleared
*/
Function resetContent (formId ){
Var clearForm = document. getElementById (formId );
If (null! = ClearForm & typeof (clearForm )! = "Undefined "){
ClearForm. reset ();
}
}
/**
* Refresh the DataGrid list (applicable to the dataGrid in Jquery Easy Ui)
* Note: We recommend that you use this method to refresh the data in the DataGrid list (that is, reload the data). You are not recommended to use the statement directly.
* $ ('# DataTableId'). datagrid ('reload'); to refresh the list data, because the latter is used, if
* When modifying a project, You Need To perform other operations in all the refresh locations in the system. Then, you will modify all updates involved in the system.
* The code is very heavy and easy to omit. However, if you use this method to refresh the list
* This requirement can be easily met without errors or omissions.
*
* @ ParamdataTableId: id of the table list on which the data DataGrid will be refreshed
*/
Function flashTable (dataTableId ){
$ ('#' + DataTableId). datagrid ('reload ');
}
/**
* Cancel row selection in the DataGrid (applicable to the dataGrid in Jquery Easy Ui)
* Note: The option "select all checkbox" cannot be canceled. However, the list must be displayed only when
* The Table on which the data DataGrid depends is placed into the most comprehensive html document, at least not before the table
* Other checkbox components.
*
* @ ParamdataTableId: target table list id of the selected data record to be canceled
*/
Function clearSelect (dataTableId ){
$ ('#' + DataTableId). datagrid ('clearselections ');
// Deselect select all in the DataGrid
$ ("Input [type = 'checkbox']"). eq (0). attr ("checked", false );
}
/**
* Close the Jquery EasyUi pop-up window (applicable to Jquery Easy Ui)
*
* @ ParamdialogId: 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: the width of each column in the list varies with the browsing width. This method is used to set the DataGrid.
* The column width can be automatically scaled in browsers with different resolutions to meet browser requirements for different resolutions.
* Usage: (for example, {field: 'ymname', title: 'number', width: fillsize (0.08), align: 'center '},)
*
* @ Parampercent percentage of the column width in the current column of the entire window (displayed in decimal form, for example, 0.3 represents 30%)
*
* @ Return the specific width calculated by the current window and the corresponding percentage
*/
Function fillsize (percent ){
Var bodyWidth = document. body. clientWidth;
Back (bodyWidth-90) * percent;
}
/**
* Obtain the row of the selected record (single choice)
*
* @ ParamdataTableId id of the table in the DataGrid list of the target record
* @ ParamerrorMessage: If no row is selected (that is, no or multiple rows are selected ),
*
* @ Return specifies the row object of the selected record. If the returned value is null or "null" (sometimes the browser converts null to the string "null"), it means no
* Select a record row.
*/
Function getSingleSelectRow (dataTableId, errorMessage ){
Var rows = $ ('#' + dataTableId). datagrid ('getselection ');
Var num = rows. length;
If (num = 1 ){
Return rows [0];
} Else {
$. Messager. alert ('message message', errorMessage, 'info ');
Return null;
}
}
/**
* Obtain the id of the selected record in the DataGrid. Multiple IDs are separated by commas (,).
* Note: the prerequisite for this method is that the idField attribute of the DataGrid corresponds to the field name in the list Json data, which must be id.
* @ ParamdataTableId id of the table in the DataGrid list of the target record
*
* @ Return the id string of the selected record (multiple IDs are separated by commas)
*/
Function getSelectIds (dataTableId, noOneSelectMessage ){
Var rows = $ ('#' + dataTableId). datagrid ('getselection ');
Var num = rows. length;
Var ids = null;
If (num <1 ){
If (null! = NoOneSelectMessage) $. messager. alert ('message 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;
}
}
/**
* Delete the selected record (applicable to the dataGrid in Jquery Easy Ui) (the Deleted field is id)
* Note: This method automatically sets the id of the selected record (the idField attribute of the DataGrid corresponds to the field name in the list Json data must be id)
* Dynamically assemble them into strings. Separate multiple ids with commas (,) (for example, 1, 2, 3, 8, and 10) and store them in the ids variable to input them to the background.
* You can use this parameter name to obtain all id strings from the request object. in this case, you can use in
* Keyword is easy to process.
* In addition, the background code must return a message in Json format in ajax format after the operation.
* The message field stores information about the user prompt, such as the success or failure of this delete operation.
*
* @ ParamdataTableId: id of the table in which the record is to be deleted
* @ ParamrequestURL interacts with the backend server and the Request Path for specific deletion operations
* @ ParamconfirmMessage Delete confirmation Information
*/
Function deleteNoteById (dataTableId, requestURL, confirmMessage ){
If (null = confirmMessage | typeof (confirmMessage) = "undefined" | "" = confirmMessage ){
ConfirmMessage = "are you sure you want to delete the selected record? ";
}
Var rows = $ ('#' + dataTableId). datagrid ('getselection ');
Var num = rows. length;
Var ids = null;
If (num <1 ){
$. Messager. alert ('message message', 'select the record you want to delete! ', 'Info ');
} Else {
$. Messager. confirm ('confirmed', 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 ('message message', data. message, 'info ');
FlashTable (dataTableId );
} Else {
$. Messager. alert ('message message', 'deletion failed! ', 'Warning ');
}
ClearSelect (dataTableId );
});
}
});
}
}