Как выделить / раскрасить таблицу, используя значения столбцов и строк?

0
In my MVC project, i have the following screen shot.
![enter image description here][1]



Output will be like this..
![enter image description here][2]
    ![enter image description here][1]




  <table id="dealer" border="1" width="150%" height="20%" class="TabAlign">
                    <tr style="background-color: #808080; color: #fff; font-size: 14px;height: 30px;">
                        <th class="center_Align">Manufacturer</th>
                        <th class="center_Align">GLI</th>
                        <th class="center_Align">Latham</th>
                        <th class="center_Align">Loop-Loc</th>
                        <th class="center_Align">Merlin</th>
                    </tr>

                    <tr style="height: 30px;">
                        <td>
                            <label for="20mil">&nbsp;&nbsp;20 MIL</label>
                            <input style="display: none;" type="text" name="20mil" value="20 Mil" id="20mil" />
                        </td>
                        <td class="right_Align">
                            @*<label for="20milgli">[email protected]_20mil_GLI.ToString("0.00")</label>*@
                            <div id="20milgli">[email protected]_20mil_GLI.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="20milgli" value="[email protected]_20mil_GLI.ToString("0.00")" id="20milgli" />
                        </td>
                        <td class="right_Align">
                            @*<label for="20milLat">[email protected]_20mil_Lat.ToString("0.00")</label>*@
                            <div id="20milLat">[email protected]_20mil_Lat.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="20milLat" value="[email protected]_20mil_Lat.ToString("0.00")" id="20milLat" />

                        </td>
                        <td class="right_Align">
                            @*<label for="20milLoop">[email protected]_20mil_Loop.ToString("0.00")</label>*@
                            <div id="20milLoop">[email protected]_20mil_Loop.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="20milLoop" value="[email protected]_20mil_Loop.ToString("0.00")" id="20milLoop" />
                        </td>
                        <td class="right_Align">
                            @*<label for="20milMer">[email protected]_20mil_Mer.ToString("0.00")</label>*@
                            <div id="20milMer">[email protected]_20mil_Mer.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="20milMer" value="[email protected]_20mil_Mer.ToString("0.00")" id="20milMer" />
                        </td>
                    </tr>
                    <tr style="height: 30px;">
                        <td>
                            <label for="2728MIL">&nbsp;&nbsp;27/28 MIL</label>
                            <input style="display: none;" type="text" name="2728MIL" value="2728MIL" id="2728MIL" />
                        </td>
                        <td class="right_Align">
                            @*<label for="2728MILgli">[email protected]_27or28mil_GLI.ToString("0.00")</label>*@
                            <div id="2728MILgli">[email protected]_27or28mil_GLI.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="2728MILgli" value="[email protected]_27or28mil_GLI.ToString("0.00")" id="2728MILgli" />
                        </td>
                        <td class="right_Align">
                            @*<label for="2728MILLat">[email protected]_27or28mil_Lat.ToString("0.00")</label>*@
                            <div id="2728MILLat">[email protected]_27or28mil_Lat.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="2728MILLat" value="[email protected]_27or28mil_Lat.ToString("0.00")" id="2728MILLat" />
                        </td>
                        <td class="right_Align">
                            @*<label for="2728MILLoop">[email protected]_27or28mil_Loop.ToString("0.00")</label>*@
                            <div id="2728MILLoop">[email protected]_27or28mil_Loop.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="2728MILLoop" value="[email protected]_27or28mil_Loop.ToString("0.00")" />
                        </td>
                        <td class="right_Align">
                            @*<label for="2728MILMer">[email protected]_20mil_Lat.ToString("0.00")</label>*@
                            <div id="2728MILMer">[email protected]_20mil_Lat.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="2728MILMer" value="[email protected]_20mil_Lat.ToString("0.00")" id="2728MILMer" />
                        </td>
                    </tr>
                    <tr style="height: 30px;">
                        <td>
                            <label for="All27or28MIL">&nbsp;&nbsp;ALL 27 or 28 MIL</label>
                            <input style="display: none;" type="text" name="All27or28MIL" value="All27or28MIL" id="All27or28MIL" />
                        </td>
                        <td class="right_Align">
                            @*<label for="All2728mil">[email protected]_27or28mil_GLI.ToString("0.00")</label>*@
                            <div id="All2728mil">[email protected]_All2728mil_GLI.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="All2728mil" value="[email protected]_All2728mil_GLI.ToString("0.00")" id="All2728mil" />
                        </td>
                        <td class="right_Align">
                            @*<label for="All2728MILLat">[email protected]_All2728mil_Lat.ToString("0.00")</label>*@
                            <div id="All2728MILLat">[email protected]_All2728mil_Lat.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="All2728MILLat" value="[email protected]_All2728mil_Lat.ToString("0.00")" id="All2728MILLat" />
                        </td>
                        <td class="right_Align">
                            @*<label for="All2728MILLoop">[email protected]_All2728mil_Loop.ToString("0.00")</label>*@
                            <div id="All2728MILLoop">[email protected]_All2728mil_Loop.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="All2728MILLoop" value="[email protected]_All2728mil_Loop.ToString("0.00")" id="All2728MILLoop" />
                        </td>
                        <td class="right_Align">
                            @*<label for="All2728MILMer">[email protected]_All2728mil_Mer.ToString("0.00")</label>*@
                            <div id="All2728MILMer">[email protected]_All2728mil_Mer.ToString("0.00")&nbsp;&nbsp;</div>
                            <input style=" display:none;" type="text" name="All2728MILMer" value="[email protected]_All2728mil_Mer.ToString("0.00")" id="All2728MILMer" />
                        </td>
                    </tr>
                </table>
<br />
                <b>Choose Manufacturer</b>
                @if (Model.ChManufacturer.Count() > 0)
                {
                    <table id="tblRadios">
                        <tr>
                            @* <td>@Html.DropDownList("manufacturer", Model.ChManufacturer, new { id = "manufacturer" })</td>*@

                            @foreach (var item in Model.ChManufacturer)
                            {
                                if (item.Text == "Select ...")
                                {
                                }
                                else
                                {
                                <td align="left">
                                    <td>
                                        <input id="manufacturer:@item.Text" type="radio" name="Manu_rbgrp" value="@item.Text" onclick="GetPatternDetails(this.value);">&nbsp;@item.Text </td>
                                    @*<td>@Html.RadioButton("ListTypes", item.Text, new { @class = "radbtn" })</td>*@
                                    @* <td>
                                        <div class="listtext">@item.Text</div>
                                    </td>*@
                                </td>
                                }
                            }
                        </tr>
                    </table>
                }

                <b>Choose Material</b>
                @if (Model.ChMaterial.Count() > 0)
                {
                    <table>
                        <tr>
                            <td></td>
                        </tr>
                        <tr>
                            @foreach (var item in Model.ChMaterial)
                            {
                                if (item.Text == "Select ...")
                                {
                                }
                                else
                                {
                                <td align="left">
                                    <td>
                                        <input id="material:@item.Text" type="radio" name="Mat_rbgrp" value="@item.Text" onclick="GetMaterialName(this.value);">&nbsp;@item.Text </td>
                                </td>
                                }
                            }

                            @*  @for (int i = 0; i < Model.ChMaterial.Count(); i++)
                            {

                                if (@Model.ChMaterial[i].Text == "Select ...")
                                {
                                }
                                else
                                {
                                <td>&nbsp;&nbsp;&nbsp;<input id="rads2:@Model.ChMaterial[i].Text" type="radio" name="Mat_rbgrp" value="@Model.ChManufacturer[i].Text">&nbsp;&nbsp;@Model.ChMaterial[i].Text
                                </td>
                                }
                            }*@
                            @*<td>@Html.DropDownList("material", Model.ChMaterial, new { id = "material" })</td>*@
                        </tr>
                    </table>
                }

Я использую Radiobutton для производителя (20mil, 2728mil и т.д.) И материал, подобный (GLI, latham, Loop-Loc и т.д.). Поэтому, если я выберу производителя как 20 мил и материал, так как Latham означает, что td ($ 2562,38) будет быть выделены. как это сделать.. любая помощь??

Теги:
asp.net-mvc
asp.net-mvc-3

2 ответа

1
Лучший ответ

Сначала вы должны найти индекс строки и столбца, а затем изменить find, что td в соответствии с indexex

Попробуйте эту скрипку

  findtdByIndex(row,column)

Выше функция возвращает td своими индексами. вы можете найти эту функцию в скрипке ниже.

http://jsfiddle.net/Pss9M/72/

0
$("#tablica tbody tr").each(function() {
   $(this).children('td:first').click(function() {
      $(this).closest('table').find('td').css({
        'background-color':''
      });
     $(this).closest('tr').find("td:nth-child(3)").css({
       'background-color':'red'
    });
  });  
});

Скриншот здесь

Ещё вопросы

Сообщество Overcoder
Наверх
Меню