How to dynamically add and remove editor_jquery from datagrid in jQueryEasyui Learning

Source: Internet
Author: User
The Edit function is relatively simple when you use easyui to edit rows. However, if you want to dynamically change other values based on the value of a box or disable a box during editing, the following describes how to add and remove the editor dynamically in easyuidatagrid. If you are interested, it is easier to use easyui to edit the editor, however, it is troublesome to dynamically change other values or disable a box during editing based on the value of a box.

For example, when a row is added, each value is manually input. The first value cannot be modified. Let's take a look at how to achieve this effect.

Easyui itself does not provide such detailed functions, so we need to expand it ourselves:

When editing, remove the editor attribute of the first column. When adding the editor attribute, add the attribute of the first column.

// Extended datagrid: add and delete editor dynamically $. extend ($. fn. datagrid. methods, {addEditor: function (jq, param) {if (param instanceof Array) {$. each (param, function (index, item) {var e = $ (jq ). datagrid ('getcolumnoption ', item. field); e. editor = item. editor ;}) ;}else {var e =$ (jq ). datagrid ('getcolumnoption ', param. field); e. editor = param. editor ;}, removeEditor: function (jq, param) {if (param instanceof Array) {$. each (param, function (index, item) {var e = $ (jq ). datagrid ('getcolumnoption ', item); e. editor ={};}) ;}else {var e =$ (jq ). datagrid ('getcolumnoption ', param); e. editor = {};}}});

Call:

Remove:

$ ("# Dg"). datagrid ('removeedit', 'cardno'); // here, cardNo is the field value of the column to be removed from the editor.

Add:

$ ("# Dg "). datagrid ('addiditor ', [// Add cardNo column editor {field: 'cardno', editor: {type: 'textbox', options: {required: true, validType: 'length [3, 3] ', invalidMessage:' enter a 3-digit number! '}}}]

Other operations can be expanded accordingly.

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.