[Easyui-grid] Adds a header menu for Easyui DataGrid, Treegrid to show or hide columns

Source: Internet
Author: User

Add a header menu for Easyui DataGrid, Treegrid, to show or hide columns

/** * @author Sun yu * * @requires jquery,easyui * * for DataGrid, Treegrid Add header menu to show or hide columns, note: Frozen columns are not in this menu*/varCreategridheadercontextmenu =function(E, field) {E.preventdefault (); varGrid = $ ( This);/*Grid itself*/    varHeadercontextmenu = This. Headercontextmenu;/*column Header Menu object on grid*/    if(!Headercontextmenu) {        varTmenu = $ (' <div style= "width:100px; ></div> '). AppendTo (' body '); varFields = Grid.datagrid (' Getcolumnfields ');  for(vari = 0; i < fields.length; i++) {            varFildoption = Grid.datagrid (' getcolumnoption '), Fields[i]); if(!Fildoption.hidden) {$ (' <div iconcls= ' Icon-ok "field=" ' + fields[i] + ' "/> '). HTML (fildoption.title). AppendTo (Tmenu); } Else {                $(' <div iconcls= ' icon-empty "field=" ' + fields[i] + ' "/> '). HTML (fildoption.title). AppendTo (Tmenu); }} Headercontextmenu= This. Headercontextmenu =Tmenu.menu ({onClick:function(item) {varfield = $ (item.target). attr (' field '); if(Item.iconcls = = ' Icon-ok ') {Grid.datagrid (' Hidecolumn ', field); $( This). Menu (' SetIcon ', {target:item.target, iconcls:' Icon-empty '                    }); } Else{Grid.datagrid (' Showcolumn ', field); $( This). Menu (' SetIcon ', {target:item.target, iconcls:' Icon-ok '                    });    }            }        }); } headercontextmenu.menu (' Show ', {left:e.pagex, top:e.pagey});}; $.fn.datagrid.defaults.onheadercontextmenu=Creategridheadercontextmenu;$.fn.treegrid.defaults.onheadercontextmenu= Creategridheadercontextmenu;

[Easyui-grid] Adds a header menu for Easyui DataGrid, Treegrid to show or hide columns

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.