Add, delete, modify, and delete a grid in Extjs4

Source: Internet
Author: User
Extdefine (& 039; JCYappcontrollerUserController & 039;, {extend: & 039; ExtappController & 039;, alias: & 039; widgetuserController & 039;, init: function () {thiscontrol ({& 039; gri
Ext. define ('jcy. app. controller. userController ', {extend: 'ext. app. controller ', alias: 'widget. userController ', init: function () {this. control ({'gridview ': {beforerender: this. beforerender }}) ;}, beforerender: function (comment, obj) {var store = comment. getStore (); // get the storevar selModel = comment of the grid. getSelectionModel (); // get the selected model/*** add */comment. down ('button [id = add] '). on ('click', function () {var addUser = Ext. cr Eate ('jcy. app. view. addUserForm '). show (); var form = addUser. down ('form'); // obtain the form var model = store. model; // obtain modelform. down ('button '). on ('click', function () {form. submit ({url: '/Extjs4/gridAction! SaveUser. action ', method: 'post', success: function (form, action) {var num = form. findField ('num '). getValue (); // obtain the value var name = form in the form. findField ('name '). getValue (); var email = form. findField ('email '). getValue (); // var data = action. response. responseText; // var json = eval ("(" + data + ")"); addUser. close (); var m = new model ({num: num, name: name, email: email}); store. add (m); // add to the end by default});/*** modify * to obtain the model first, and then create the mode with data. L **/comment. down ('button [id = edit] '). on ('click', function () {var record = selModel. getSelection (); // obtain the selected data if (record. length = 1) {var editUser = Ext. create ('jcy. app. view. addUserForm '); editUser. setTitle ('modify user information'); editUser. setIconCls ('table _ edit'); editUser. down ('form '). loadRecord (record [0]); // load information var text = editUser. down ('form '). down ('textfield'); text. readOnly = true; editUser. show (); var form = editUser. down (' M'); editUser. down ('click'). on ('click', function () {form. submit ({url: '/Extjs4/gridAction! EditUser. action ', method: 'post', success: function (form, action) {var num = form. findField ('num '). getValue (); // obtain the value var name = form in the form. findField ('name '). getValue (); var email = form. findField ('email '). getValue (); editUser. close (); var model = store. model; // obtain modelvar m = new model ({num: num, name: name, email: email}); store. add (m); // add to the end by default // store. insert (0, m); // The first is the insert position});} else {Ext. msg. alert ("prompt", "select a piece of data! "). SetIcon ("ext-mb-info") ;}});/*** Delete */comment. down ('button [id = del] '). on ('click', function () {if (selModel. hasSelection () {var selected = selModel. getSelection (); var ids = []; Ext. each (selected, function (item) {ids. push (item. data ['num']); // alert (item. get ('num') ;}); Ext. msg. confirm ('hint ', 'Are you sure you want to delete', function (B) {if (B = 'yes') {Ext. ajax. request ({url: '/Extjs4/gridAction! DelUser. action ', params: {ids: ids}, method: 'post', success: function (response) {Ext. array. each (selected, function (record) {store. remove (record); // Delete the data in the grid}) ;}}}) ;}} else {Ext. msg. alert ("prompt", "You have not selected the data to be modified! "). SetIcon ("ext-mb-info "). setWidth (200) ;}}) ;}, models: ['jcy. app. model. gridModel '], stores: ['jcy. app. store. gridstore'], views: ['jcy. app. view. gridView ', 'jcy. app. view. gridview2', 'jcy. app. view. addUserForm ']});

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.