扩展jQuery easyui datagrid增加动态改变列编辑的类型(treegrid也适用)

  • Post author:
  • Post category:其他



01

$.extend($.fn.datagrid.methods, {


02



addEditor :


function


(jq, param) {


03



if


(param


instanceof


Array) {


04



$.each(param,


function


(index, item) {


05



var


e = $(jq).datagrid(


'getColumnOption'


, item.field);

06



e.editor = item.editor;

07



});

08



}


else


{


09



var


e = $(jq).datagrid(


'getColumnOption'


, param.field);

10



e.editor = param.editor;

11



}

12



},

13



removeEditor :


function


(jq, param) {


14



if


(param


instanceof


Array) {


15



$.each(param,


function


(index, item) {


16



var


e = $(jq).datagrid(


'getColumnOption'


, item);

17



e.editor = {};

18



});

19



}


else


{


20



var


e = $(jq).datagrid(


'getColumnOption'


, param);

21



e.editor = {};

22



}

23



}

24

});


使用方式:





为password字段添加一个editor



1

$(


"#gridId"


).datagrid(


'addEditor'


, {


2



field :


'password'


,

3



editor : {


4



type :


'validatebox'


,

5



options : {


6



required :


true

7



}

8



}

9



});


删除password的editor



1

$(


"#gridid"


).datagrid(


'removeEditor'


,


'password'


);



注:两个方法,第二个参数都可以传递数组。






treegrid也可以直接这样扩展。




http://easyui.btboys.com/post-83.html