开发者

Prototype plugin for expanding table rows?

开发者 https://www.devze.com 2023-03-29 22:06 出处:网络
jQuery has a plugin call开发者_JAVA百科ed jExpand for expanding table rows. Does Prototype have an equivalent?The source of jExpand is so small I just went ahead and translated it for you.

jQuery has a plugin call开发者_JAVA百科ed jExpand for expanding table rows. Does Prototype have an equivalent?


The source of jExpand is so small I just went ahead and translated it for you.

Element.addMethods(
    'TABLE',
    {
        addJExpand : function(elem){
            elem = $(elem);
            elem.select('tr:nth-child(even)').each(function(child){child.addClassName('odd')});
            elem.select('tr:nth-child(odd)').each(Element.hide);
            elem.down('tr').show();
            elem.select('tr:nth-child(even)').each(
                function(child){
                    child.observe('click', 
                        function(){
                            child.next().toggle();
                        }
                    );
                }   
            );
        }
    }
);

Just call it using table.addJExpand(), where table is your prototype-extended variable. You can also use Element.addJExpand for times when you're using .each.

You're welcome.

0

精彩评论

暂无评论...
验证码 换一张
取 消