Добавить стиль для полосатой таблицы, включая функцию наведения - PullRequest
1 голос
/ 04 июля 2019

У меня есть таблица с полосатым стилем:

<div class="container" ng-app="sortApp" ng-controller="mainController">
  <table class="profile-table">
    <thead>
      <tr>
        <th>MONTH</th>
        <th>PROJECT</th>
        <th>ACHIEVEMENT (%)</th>
        <th>TOTAL OUTPUT</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="bnty in bntyList">
        <td hover-class="hover" ng-if="!bnty.catRowMatch" rowSpan="{{bnty.rows}}">{{ bnty.month }} </td>
        <td hover-class="hover">{{ bnty.ih_project }}</td>
        <td hover-class="hover">{{ bnty.ih_output }}</td>
        <td hover-class="hover" ng-if="!bnty.catRowMatch" rowSpan="{{bnty.rows}}">{{ bnty.ih_sum_output }}</td>
      </tr>
    </tbody>
  </table>
</div>

В настоящее время я хочу достичь двух вещей:

  1. Изменить полосатый стиль в соответствии с натянутыми строками.

Теперь это так: enter image description here

Но я хочу сделать это так: enter image description here

2. То же самое я хочу сделать с зависанием.Есть ли способ наведения целого ряда следующим образом: enter image description here

Вот скрипка

1 Ответ

2 голосов
/ 04 июля 2019

Я внес некоторые изменения в ваш код.Может быть, это поможет вам решить вашу проблему.

Скрипка: Скрипка

angular.module('sortApp', [])

  .controller('mainController', function($scope) {
    $scope.bntyList = [{
        month: "January",
        ih_project: "FRS BGD COL",
        ih_output: "12.00",
        ih_sum_output: "65.00",
        catRowMatch: false,
        rows: 3
      },
      {
        month: "January",
        ih_project: "FRS BGD LYT",
        ih_output: "34.30",
        ih_sum_output: "65.00",
        catRowMatch: true,
        rows: 2
      },
      {
        month: "January",
        ih_project: "HRD BGD COL",
        ih_output: "67.60",
        ih_sum_output: "65.00",
        catRowMatch: true,
        rows: 1
      },
      {
        month: "February",
        ih_project: "ENC2 BGD COL",
        ih_output: "77.00",
        ih_sum_output: "80.00",
        catRowMatch: false,
        rows: 2
      },
      {
        month: "February",
        ih_project: "ENC2 BGD LYT",
        ih_output: "90.00",
        ih_sum_output: "80.00",
        catRowMatch: true,
        rows: 1
      }
    ];
  });

angular.module('sortApp').directive("hoverClass", function() {
  return {
    restrict: 'A',
    scope: {
      hoverClass: '@'
    },
    link: function(scope, element) {
      element.on('mouseenter', function() {
        $el = $(this);
        console.log($el);
        $el.parent().addClass("hover");
        /* if ($el.parent().has('td[rowspan]').length == 0)
          $el.parent().prevAll('tr:has(td[rowspan]):first').find('td[rowspan]').addClass("hover"); */
      });
      element.on('mouseleave', function() {
$el.parent().removeClass("hover").prevAll('tr:has(td[rowspan]):first').find('td[rowspan]').removeClass("hover");
      });
    }
  };
});
body {
  padding-top: 50px;
}

.profile-table {
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  margin-bottom: 1rem;
  background-color: transparent;
  text-align: left;
}

.profile-table th,
.profile-table td {
  padding: 1.1rem 0;
  vertical-align: top;
  font-size: 14px;
}

.profile-table thead th {
  vertical-align: bottom;
  /*border-bottom: 2px solid #ebedf2;*/
}

.profile-table tbody:nth-of-type(odd) {
  background-color: #F0F0F0;
}

tbody:hover {
  border: 2px solid #E56590;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div class="container" ng-app="sortApp" ng-controller="mainController">
  <table class="profile-table">
    <thead>
      <tr>
        <th>MONTH</th>
        <th>PROJECT</th>
        <th>ACHIEVEMENT (%)</th>
        <th>TOTAL OUTPUT</th>
      </tr>
    </thead>
    <tbody ng-repeat="bnty in bntyList" ng-if="!bnty.catRowMatch">
      <tr ng-repeat="bnty1 in bntyList" ng-show="(bnty.month == bnty1.month)">
        <td  ng-if="!bnty1.catRowMatch" rowSpan="{{bnty1.rows}}" >{{ bnty1.month }} </td>
        <td >{{ bnty1.ih_project }}</td>
        <td >{{ bnty1.ih_output }}</td>
        <td ng-if="!bnty1.catRowMatch" rowSpan="{{bnty1.rows}}" >{{ bnty1.ih_sum_output }}</td>
      </tr>
    </tbody>
  </table>
</div>
...