Extjs General CRUD Method

Source: Internet
Author: User

Extjs General CRUD method, you can complete CRUD of extjs table as long as you input the corresponding parameters

Code:

/**
* Add events
* @ Param {} saveButton
* @ Param {} gridObj
* @ Param {} idName
* @ Param {} treeObj
* @ Param {} url
* @ Param {} extends func
* @ Returns {}
*/
Function commGridInsertAction (saveButton, gridObj, idName, treeObj, url, javasfunc ){
If (saveButton! = Null & saveButton! = Undefined ){
If (then func ){
Using func ();
}
SaveButton. on ("click", function (){
Var sd = gridObj. getStore ();
Conn. request ({
Url: url,
Params :{},
Success: function (response, opts) {// operation successful
Var obj = Ext. decode (response. responseText) [0];
Var Plant = gridObj. getStore (). recordType;
Var p = new Plant (obj );
GridObj. stopEditing ();
Sd. insert (0, p );
GridObj. startEditing (0, 2 );
},
Failure: function () {// failed operation
Ext. Msg. alert ("prompt", "failed to add data ...");
}
})
});
}
}
/**
* Delete an event
* @ Param {} deleteButton
* @ Param {} gridObj
* @ Param {} idName
* @ Param {} treeObj
* @ Param {} url
* @ Param {} extends func
* @ Returns {}
*/
Function commGridDeleteAction (deleteButton, gridObj, idName, treeObj, url, params, role func ){
If (deleteButton! = Null & deleteButton! = Undefined ){
If (then func ){
Using func ();
}
DeleteButton. on ("click", function (B, e ){
Var sd = gridObj. getStore ();
Var rs = gridObj. getSelectionModel (). getSelections ();
Var length = rs. length;
If (length> 0 ){
Var ids_data = "";
Var dis_array = new Array ();
For (var I = 0; I <length; I ++ ){
If (I = 0 ){
Ids_data = rs [I]. get (idName );
} Else {
Ids_data = ids_data + "," + rs [I]. get (idName );
}
Dis_array.push (rs [I]. get (idName ));
}
Var para = params;
Para [idName] = ids_data;
Conn. request ({
Url: url,
Params: para,
Success: function (response) {// successful operation
Sd. reload ();
// Cyclically Delete the junk data of gird
For (var I = 0; I <length; I ++ ){
Sd. remove (rs [I]);
}
Ext. example. msg ("Reminder", "you have deleted data ");
},
Failure: function () {// failed operation
Ext. Msg. alert ("prompt", "failed to delete data ...");
}
})
} Else {
Ext. Msg. alert ("prompt", "You have not selected the data to be deleted ...");
}
})
}
}
/**
* Batch update
* @ Param {} listupdate
* @ Param {} gridObj
* @ Param {} treeObj
* @ Param {} url
* @ Param {} extends func
* @ Param {} canUpdateFields
* @ Returns {}
*/
Function commGridListUpdateAction (listupdate, gridObj, treeObj, url, javasfunc, canUpdateFields ){
If (listupdate! = Null & listupdate! = Undefined ){
If (then func ){
Using func ();
}
Listupdate. on ("click", function (){
Var sd = gridObj. getStore ();
Var objs = sd. getModifiedRecords ();
Var objData = new Array ();
Var model = null;
If (objs. length = 0 ){
Ext. example. msg ("Reminder", "no data to be saved ");
Return;
} Else {
For (var I = 0; I <objs. length; I ++ ){
Model = {};
$. Each (canUpdateFields, function (k, v ){
Model [k] = objs [I]. get (k );
});
ObjData. push (model );
}
Conn. request ({
Url: url,
Params: {strData: JSON. stringify (objData )},
Success: function (response, opts) {// operation successful
Var I = response. responseText;
For (var j = 0; j <objs. length; j ++) {// remove the modified red flag.
Objs [j]. commit ();
J --;
}
Ext. example. msg ("Reminder", "you have successfully modified" + I + "data entries ");
},
Failure: function () {// failed operation
Ext. Msg. alert ("prompt", "failed to save data ...");
}
})
}
})
}
}

Code:

/**
* Data dictionary table time registration
* @ Param {} gridObj
* @ Param {} idName
* @ Param {} treeObj
* @ Returns {}
*/
Function userGridEventMonitor (gridObj, idName, treeObj ){
/** Add event */
Var saveButton = gridObj. getTopToolbar (). findById ("save-user ");
New commGridInsertAction (saveButton, gridObj, idName, treeObj, "/dept/userAction. action? FunctionName = insertUser & checkNodeId = "+ gridObj. store. baseParams [" checkNodeId "]);
/** Delete event */
Var deleteButton = gridObj. getTopToolbar (). findById ("delete-user ");
New commGridDeleteAction (deleteButton, gridObj, idName, treeObj, "/dept/userAction. action? FunctionName = deleteUser & cascadeType = CASCADE ",
{UserId :{}, null );
/** Batch update events */
Var listupdate = gridObj. getTopToolbar (). findById ("listupdate-user ");
New commGridListUpdateAction (listupdate, gridObj, treeObj,
"/Dept/userAction. action? FunctionName = listupdate ",
Null, {"userId": null,
"Username": null,
"ChineseName": null,
"Password": null,
"UpdateDate": null,
"Enabled": null,
"OrderIndex": null,
"DeptId": null}
);
/** Double-click a Department event */
GridObj. on ("celldblclick", function (g, rowIndex, columnIndex, e ){
Var sd = g. getStore ();
Var cm = g. getColumnModel ();
Var id = cm. getDataIndex (columnIndex );
If ("deptId" = id ){
Var deptID = sd. getAt (rowIndex). get ("deptId ");
Var tree = new sms. treeDicWin. treeDicWin ({width: 250, height: 500,
Url: "/dept/deptAction. action? FunctionName = loadDept4Tree & showCheckbox = true & deptId = ",
Text: "Haydon is a company", idName: "userId", DicidName: "deptId", g: g, rowIndex: rowIndex, columnIndex: columnIndex });
Tree. show ();
} Else if ("photosAdd" = id ){
Var dialog = new Ext. ux. UploadDialog. Dialog ({
Url: 'upload. jsp ',
Reset_on_hide: false,
AutoCreate: true,
Closable: true,
Allow_close_on_upload: true,
Permitted_extensions: ['jpg ', 'jpg', 'jpeg ', 'jpeg', 'gif', 'gif'],
Base_params: {className: "com. hd. department. model. user "}
Upload_autostart: false
});
Dialog. show ();
Dialog. on ("uploadsuccess", function (dialog, filename, resp_data, record ){

});
}

});

Related Article

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.