2014-02-17 29 views
1

我有幾個特點麻煩我想要實現:角+引導:表設計

  • 我希望有一個固定的表頭,所以我可以向下滾動,同時仍然能夠看到頭,我去通過數據。
  • 我希望我的表格的尺寸儘可能大=>不溢出-x
  • 我的列可以來自不同的尺寸,但標頭必須對齊。
  • 我的< td>必須限制最大高度,並在td內添加一個滾動條。

這些甚至可能嗎?因爲我嘗試了幾種解決方案inconclusives =(

如果我從表中分離出來的頭,它會弄亂寬度的列標題的。

.test { 
    overflow-x: visible; 
    overflow-y: auto; 
} 

如果您正在使用的上溢可見。-x或溢出-Y和比其他可見光以外的某種可見的值被解釋爲自動

而這將無法正常工作。

編輯@Merijn DK

<!-- html --> 
<table class="table table-striped table-bordered"> 
    <thead> 
     <tr> 
      <th ng-repeat="column in columns" ng-show="column.show" ng-style="column.style"> 
       {{ column.label }} 
      </th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="item in results"> 
      <td ng-repeat="column in columns" ng-show="column.show" ng-style="column.style" ng-bind-html="item.data | unsafe"> 
      </td> 
     </tr> 
    </tbody> 
</table> 

//Javascript 
.filter('unsafe', function($sce, $rootScope) { 
    return function(html) { 
     return $sce.trustAsHtml(html); 
    }; 
}); 
+0

嗨,謝謝你的回答。這個問題並不是要求人們爲我編碼。我已經有了桌子,數據格式完美。這是關於設計(你可以看標題)。你說這是可能的,請告訴我。我搜索了很多東西,而且我總是試圖總是隻用於一種情況的相同方法。我已經給出了我嘗試過的例子。 – Romain

+0

thanx你越來越近。你也可以發佈你的頭文件的樣式嗎? –

+0

即時通訊相當確定http://www.fixedheadertable.com/將做順便說一句。你確定你嘗試過嗎?你包括jquery等? –

回答

3

只是找到了一個不錯的插件,允許浮動或以各種方式固定theads。 Just look at the awesome demos here

現在你需要實現角度。我做了一個非常快的和不完善的指令,它可以改善很多:(媒體鏈接通過@spades自己提高,THX爲是真棒!)

plunker.directive('thead', function() { 
    return { 
    restrict: 'A', 
    scope: { 
     ngModel: '=' 
    }, 
    link: function(scope, elem) { 
     window.onscroll = function() { 
      elem.floatThead({ 
       scrollingTop: 45, 
      }); 
      elem.floatThead('reflow'); 
     } 
    } 
    }; 
}) 

您可以通過這裏加入他們試訓的各種選項:

elem.floatThead(additionaloptions); 

只需添加指令你的HTML:

<table thead> 
    <thead> 
     <tr> 
     <th>a</th> 
     <th>b</th> 
     <th>c</th> 
     <th>d</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td>111</td> 
     <td>111</td> 
     <td>111</td> 
     <td>111</td> 
     </tr> ... 

找到一個完整plunker(帶有示例的窗口滾動)here(當然這也可能發生,我請注意,您應該在新窗口(右上角的藍色x)中打開預覽,並調整其高度,直到滾動條出現爲止。

+0

我幾乎說得對:http://imgur.com/HOPDPdN&EgPHLxU#1 但是當我向下滾動時:http://imgur.com/HOPDPdN&EgPHLxU#0 – Romain

+0

嗯,很難說這是從哪裏來的,沒有你最終的碼。這是另一個讓我更加關注你最初的問題http://plnkr.co/edit/pbfDxTutsIaaPkVYw8tR?p=preview。 (我現在無法實現safehtml)。但總的來說,它是有效的。也許玩jQuery插件的選項。正如我所說,我沒有寫它,但幾天前在DailyJS上發現它,並認爲:嘿,這可能在某一天有用:-)我現在將停止工作,並且明天回顧你的預告。晚上好:-) – mainguy

+0

還有saferHtml =) http://plnkr.co/edit/L9sD4DStrTImMyot8CXu?p=preview – Romain