Table restore and redo

        revertTable: function (obj) {

            $("tr", obj).each(function (trindex, tritem) {

                $($(tritem).find("th").toArray().reverse()).each(function (tdindex, tditem) {

                    var rowspanCount = !!$(tditem).attr("rowspan")?parseInt($(tditem).attr("rowspan")):1;

                    var colspanCount = !!$(tditem).attr("colspan")?parseInt($(tditem).attr("colspan")):1;

                    var value = $(tditem).text();

                    var newtd = "<th data-flag='F'>" + value + "</th>";

                    if (rowspanCount > 1) {

                        var parent = $(tditem).attr("data-rowspan",rowspanCount).parent("tr")[0];

                        while (rowspanCount-- > 1) {

                            $(parent).next().prepend(newtd);

                            parent = $(parent).next();

                        }

                        $(tditem).removeAttr("rowspan", 1);

                    }

                    if (colspanCount > 1) {

                        $(tditem).attr("data-colspan",colspanCount);

                        while (colspanCount-- > 1) {

                            $(tditem).after(newtd);

                        }

                        $(tditem).removeAttr("colspan");

                    }

                });

            });

        },

        redoTable:function(obj){

            $("th[data-flag]",obj).remove();

            $("th[data-colspan]",obj).each(function(i,v){

                $(this).attr("colspan",$(this).attr("data-colspan")).removeAttr("data-colspan");

            });

             $("th[data-rowspan]",obj).each(function(i,v){

                $(this).attr("rowspan",$(this).attr("data-rowspan")).removeAttr("data-rowspan");

            });

        },

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042092&siteId=291194637