In ext4 grid, click the button to use rowedit to create a record + cancel deleting the new record

Source: Internet
Author: User

The expected results are as follows:

1. Click "new file" to add a default record

2. Click Update to write data to the database, clear the dirty tag, and write the returned ID to the store.

3. Click Cancel to delete the new record.

Pay attention to the following points:

1. The new record is marked with the phantom attribute. If the value of phantom = true is not uploaded, the record is deleted when cancel is clicked.

2. rowedit does not provide the cancel button event and must overwrite the canceledit () function.

3. When the grid is loaded, the canceledit () of rowedit is triggered, and the row is deleted ...... (Why ???? Bug !!) Therefore, a flag must be configured; otherwise, an infinite loop may occur.

The method is as follows:

VaR newsignal = 'normal ';

1. Add the button to the grid and add the click event. Note that the flag is set. Otherwise, click again. Use the editing of rowedit to set the flag to OK, but use the next one, therefore, this flag has three states, so you can write it now.

 Dockeditems: [{xtype: 'toolbar', CLS: 'x-docked-noborder-top', items: [{text: 'New file', iconcls: 'icon-New-topic ', Handler: function () {If (newsignal = 'normal') {// create a record instance through the modelmanager var r = ext. modelmanager. create ({Title: 'New file A', classid: '3384fcb7-3106-4fdd-ab65-31152eef9edb', typeid: '9b6d5105-reta', datetimecreated: ext. date. cleartime (new date ()}, 'file'); Ext. getstore ('filesstore '). insert (0, R); newsignal = 'newing '; rowediting. startedit (ext. getstore ('filesstore '). first (), this. ownerct. ownerct. columns [0]) ;}}]

2. Override the canceledit () function. Note that the store. findby () function receives a function as the parameter. If function () returns true, the result is a qualified result.

 VaR rowediting = ext. create ('ext. grid. plugin. rowediting ', {ID: 'rowediting', autocancel: false, clickstoedit: 2, // override unedit method, add your own business logic (create a file and click rollback) // here, a flag must be added to avoid infinite loop errors. Because the grid load and store remove will cause canceledit // you can use the phantom attribute and Boolean canceledit to determine whether there is a new meter: function () {var me = this; if (Me. editing) {me. geteditor (). canceledit (); store = ext. getstore ('filesstore'); var n = store. findby (function ( R) {return (R. Phantom = true)}) if (newsignal = 'newing ') {If (n! =-1) {store. removeat (n) ;}newsignal = 'normal' ;}}, listeners: {EDIT: function onedit (E) {// execute an xhr to send/commit data to the server, in callback do (if successful): E. store. sync ();}}});

3. You need to use the callback function when you click Update. refer to the previous article and I will not write it here (because the bug in IE cannot be solved, temporarily discard roweditor, use a custom Panel to modify data). If you are interested, refer to the above

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.