简体   繁体   English

剑道树列表上方的额外行

[英]Extra row atop Kendo Treelist

We have a Kendo TreeList that works fine. 我们有一个可以正常工作的Kendo TreeList。 Data shows, everything shows in the hierarchy correctly. 数据显示,一切都正确显示在层次结构中。 The problem is, we need to group each two columns into another "superset" group. 问题是,我们需要将每两列分组为另一个“超集”组。

该图显示了具有超集组的TreeList

The column headings (the names above are not real) are too long if not grouped as shown, and they lose useful context. 如果未按所示进行分组,则列标题(上面的名称不是真实的)太长,并且它们失去了有用的上下文。

I tried adding an HTML table above the TreeList, but that doesn't look right. 我尝试在TreeList上方添加一个HTML表,但这看起来并不正确。 And it doesn't work if the user resizes the columns. 如果用户调整列的大小,它将不起作用。 Also the toolbar (for Excel export) is in the way, so it doesn't even look like it's part of the TreeList. 工具栏(用于Excel导出)也很麻烦,因此它甚至看起来都不是TreeList的一部分。

I also looked at wrapping the text in the columns, but from what I've seen, that's really iffy too. 我还查看了将文本包装在各列中的情况,但是从我所看到的情况来看,这也确实很困难。

It seems like an extra row as shown above (with the ability to merge some columns, like with an HTML table) is the best way to go. 最好是上面所示的额外行(具有合并某些列的功能,例如使用HTML表)。 Despite scouring the web, I couldn't find a way to do this. 尽管搜寻了网络,但我找不到方法。 Is this even possible with a Kendo TreeList? 使用Kendo TreeList甚至可能吗?

This has been solved. 这已经解决了。 Not by me, but by another developer on our team who's insanely good at JavaScript. 不是我本人,而是我团队中另一个精通JavaScript的开发人员。

The trick is to edit the TreeList's HTML and CSS through JavaScript. 诀窍是通过JavaScript编辑TreeList的HTML和CSS。 You can bind to any event, but we do it on page load: 您可以绑定到任何事件,但是我们在页面加载时进行绑定:

<script>
$(document).ready(function () {
    // anything in here will get executed when the page is loaded
    addTopRowToTreeList();
});

function addTopRowToTreeList() {

    // grab the thead section
    // your HTML may be different
    var foo = $('#MyTreeList').children('div.k-grid-header').children('div.k-grid-header-wrap');
    var tableChild = foo.children('table');
    var headChild = tableChild.children('thead');

    var bottomRow = headChild.children('tr');
    var topRow = $('<tr>').attr('role', 'row');

    // bottom cell should draw a border on the left
    bottomRow.children('th').eq(0).addClass('k-first');

    // add blank cell 
    var myNewCell = $('<th>').addClass('k-header').attr('colspan', '1')
    var headerString = '';
    var headerText = $('<span>').addClass('k-link').text(headerString);
    myNewCell.append(headerText);
    topRow.append(myNewCell);

    // ... add remaining cells, like above

    headChild.prepend(topRow);
}
</script>

That's all there is to it! 这里的所有都是它的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM