DataTables自动列隐藏点击展开仅显示GroupClass列该如何修复
问题根因
- 现有format函数错误将
GroupClass字段视为数组进行遍历,从你的列定义可以看出该字段是普通值类型,遍历逻辑本身就无法正常输出内容 - 仅实现了
GroupClass单字段的渲染逻辑,未包含你需要展示的Crisis Appt Time列右侧剩余4个字段:ClientAvailability、AssignmentNotes、ContactNotes、ReferralDescription
修复方案
直接替换你代码末尾的format函数为以下代码即可:
function format(d) { // 按需求展示Crisis Appt Time右侧所有列 return `<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px; width:100%"> <tr> <th style="width:20%; text-align:left;">Group Class</th> <td>${d['@nameof(searchResultViewModel.GroupClass)'] || '-'}</td> </tr> <tr> <th style="width:20%; text-align:left;">Client Availability</th> <td>${d['@nameof(searchResultViewModel.ClientAvailability)'] ? `<div class="scrollingCell">${d['@nameof(searchResultViewModel.ClientAvailability)']}</div>` : '-'}</td> </tr> <tr> <th style="width:20%; text-align:left;">Assignment Notes</th> <td>${d['@nameof(searchResultViewModel.AssignmentNotes)'] ? `<div class="scrollingCell">${d['@nameof(searchResultViewModel.AssignmentNotes)']}</div>` : '-'}</td> </tr> <tr> <th style="width:20%; text-align:left;">Contact Notes</th> <td>${d['@nameof(searchResultViewModel.ContactNotes)'] ? `<div class="scrollingCell">${d['@nameof(searchResultViewModel.ContactNotes)']}</div>` : '-'}</td> </tr> <tr> <th style="width:20%; text-align:left;">Referral Description</th> <td>${d['@nameof(searchResultViewModel.ReferralDescription)'] ? `<div class="scrollingCell">${d['@nameof(searchResultViewModel.ReferralDescription)']}</div>` : '-'}</td> </tr> </table>`; }
补充说明
- 保留了你原有列定义中长文本字段的
scrollingCell滚动样式,和主表展示逻辑保持一致 - 空值字段统一输出
-避免页面空白 - 沿用Razor的
@nameof语法获取字段名,避免硬写字段名出现拼写错误
内容的提问来源于stack exchange,提问作者Masterolu
相关产品推荐
相关产品推荐

