合并单元格重复值

时间:2016-06-03 07:49:17

标签: javascript jquery

这是图像 enter image description here

<table id="tblSample">
                                <!--Heading-->
                                <tbody>
                                                                            <th>Super Partner</th><th>Products</th><th></th>
                                    <th>Plan</th><th>Actual</th><th>Difference</th><th>%</th>
                                    <th>Plan</th><th>Actual</th><th>Difference</th><th>%</th>
                                    <th>Plan</th><th>Actual</th><th>Difference</th><th>%</th>
                                    <th>Plan</th><th>Actual</th><th>Difference</th><th>%</th>
                                    <th>Total Plan</th><th>Actual YTD + Plan</th><th>Difference</th><th>%</th>
                                </tr>




                                                                            <tr class="getfor counter_row_0 hide_other_prtnr" colspan="" for="20" id="myTable">
                                            <td style="border-top:1px solid #ddd;border-bottom:none;" class="inner_for">
                                                Gagan                                               </td>
                                        </tr>
                                                                                        <tr class="counter_row_0 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 1</td>

                                                                                                    </tr>
                                                                                            <tr class="counter_row_0 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 2</td>


                                                                                                    </tr>




                                                                                    <tr class="getfor counter_row_1 hide_other_prtnr" colspan="" for="20" id="myTable">
                                            <td style="border-top:1px solid #ddd;border-bottom:none;" class="inner_for">
                                                Gagan                                               </td>
                                        </tr>
                                                                                        <tr class="counter_row_1 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 10</td>
                                            </tr>
                                                                                            <tr class="counter_row_1 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Monika_Testing_Product</td>


                                                                                                    </tr>




                                                                                    <tr class="getfor counter_row_2 hide_other_prtnr" colspan="" for="20" id="myTable">
                                            <td style="border-top:1px solid #ddd;border-bottom:none;" class="inner_for">
                                                Gagan                                               </td>
                                        </tr>
                                                                                        <tr class="counter_row_2 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 1</td>
                                                        </tr>
                                                                                            <tr class="counter_row_2 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 2</td>
                                                </tr>
                                                </tr>
                                                                                            <tr class="counter_row_2 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 3</td>
                                                        </tr>
                                                                                            <tr class="counter_row_2 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 4</td>
                                                                    </tr>
                                                                                        <!--   cam total total  -->

                                        </tr>

                                                                                    <tr class="getfor counter_row_3 hide_other_prtnr" colspan="" for="21" id="myTable">
                                            <td style="border-top:1px solid #ddd;border-bottom:none;" class="inner_for">
                                                Gaurav                                              </td>
                                        </tr>
                                                                                        <tr class="counter_row_3 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 10</td>
                                                                </tr>
                                                                                            <tr class="counter_row_3 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Monika_Testing_Product</td>

                                        </tr>


                                        </tr>

                                                                                    <tr class="getfor counter_row_4 hide_other_prtnr" colspan="" for="22" id="myTable">
                                            <td style="border-top:1px solid #ddd;border-bottom:none;" class="inner_for">
                                                RaviKant                                                </td>
                                        </tr>
                                                                                        <tr class="counter_row_4 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Macross Sales</td>

                                                                                                    </tr>
                                                                        </tr>
                                                                                            <tr class="counter_row_4 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales infinity</td>
                                                                                </tr>
                                                                        </tr>
                                                                                            <tr class="counter_row_4 hide_other_prtnr">
                                                <td style="border:none;"></td>
                                                <td rowspan="2">Sales Play 3</td>
                                                                            </tr>


                                        </tr>







<script>
    $(document).ready(function() {
        var span = 1;
        var prevTD = "";
        var prevTDVal = "";
        $("#myTable td:first-child").each(function() { //for each first td in every tr
            var $this = $(this);
            if ($this.text() == prevTDVal) { // check value of previous td text
                span++;
                if (prevTD != "") {
                    // prevTD.attr("rowspan", span); // add attribute to previous td
                    $this.text("");// remove current td
                    // $this.attr("rowspan","1");
                }
                } else {
                prevTD     = $this; // store current td 
                prevTDVal  = $this.text();
                span       = 1;
            }
        });

        var count_row = [] ;
        var unique_for = [] ;
        $(".getfor").each(function(){
            var for_data = $(this).attr('for') ;
            var row_count = $(this).find(".inner_for").attr('rowspan');
            if(jQuery.inArray(for_data, unique_for) == -1)
            {
                count_row[for_data] = row_count;
                unique_for.push(for_data);
            }
            else
            {
                count_row[for_data] = parseInt(count_row[for_data]) + parseInt(row_count) ;
            }
        });
        alert(count_row);
        $.each(count_row, function() {
            var key = Object.keys(this)[0];
            var value = this[key];

            if(value > 0 ){




            //unique_for.setAttribute("rowspan",count_row);
            //alert(value+' : key : ' +key);
            }
        })

    });


    </script>

我只想要填充的空单元格与“Gagan”结合。在上面的代码中我只清空重复的名称,但现在我想要gagan名称应该在单元格的中间变化。

0 个答案:

没有答案