After several attempts to see where the issue was in the snippets, I changed the name of the snippet and added it to the snippet and it worked
.grouped-levels table tbody:has(a[href^="#explain"]){
border: 2px solid yellow;
/* background-color: grey; /* */
& td {
border-right: 2px solid blue;
}
& td:has(a[href^="#explain"]) {
& a[href^="#explain"] {
display: none;
}
border-top: 2px solid green;
}
}
Apart from the fact that the order in your table is inaccurate and problematic, it only works if the values are ordered in descending or ascending order in the title column for each of the values in level 2, as shown here:
Also, regardless of the fact that my table and your table all the values in them that are in level 1 and level 2 appear in the first row as well as not in the middle of the results, and this is an optimization that I want to apply, but when doing this optimization, your snippet will definitely not work well, so I modified the dataviewjs query to make the values in level one and two centralize the results by using a new concept and fixing the aforementioned order issue and came up with this:
The Table
```dataviewjs
const level1 = "Section";
const level2 = "Topic";
const tableRows = dv
.pages()
.where(p => p[level1] && p[level2] && p.title)
.sort(p => [p[level1], p[level2], p.title].join("/"))
.map(p => [p[level1], p[level2], `[[${p.title}]]`])
.array();
let firstCol = "";
let secondCol = "";
let firstColCount = 0;
let secondColCount = 0;
let firstColMiddleIndex = 0;
let secondColMiddleIndex = 0;
let firstColStartIndex = 0;
let secondColStartIndex = 0;
for (let i = 0; i < tableRows.length; i++) {
const row = tableRows[i];
if (firstCol !== row[0]) {
firstCol = row[0];
firstColStartIndex = i;
firstColCount = tableRows.filter(r => r[0] === firstCol).length;
firstColMiddleIndex = firstColStartIndex + Math.floor((firstColCount - 1) / 2);
secondCol = "";
if (i !== firstColMiddleIndex) {
row[0] = `<span class="highlight">#line</span>`;
} else {
row[0] = `<span class="highlight">${firstCol} #line</span>`;
}
} else if (i === firstColMiddleIndex) {
row[0] = `<span class="highlight">${firstCol}</span>`;
} else {
row[0] = "";
}
if (secondCol !== row[1]) {
secondCol = row[1];
secondColStartIndex = i;
secondColCount = tableRows.filter(r => r[1] === secondCol).length;
secondColMiddleIndex = secondColStartIndex + Math.floor((secondColCount - 1) / 2);
if (i !== secondColMiddleIndex) {
row[1] = `<span class="highlight">#line</span>`;
} else {
row[1] = `<span class="highlight">${secondCol} #line</span>`;
}
} else if (i === secondColMiddleIndex) {
row[1] = `<span class="highlight">${secondCol}</span>`;
} else {
row[1] = "";
}
row[2] = `<span class="highlight">${row[2]} #line</span>`;
}
// Display the table
dv.table(["Section", "Topic", "Title"], tableRows);
dv.container.classList.add("grouped-levels");
The table simply checks the value that is in the middle of the results in levels 1 and 2 and sees if this value is in the first row in its part (the part in which the value is repeated) in the table or if it is in another row in its part in the table. If it is in the first row, the table writes #line next to the value. If the value is not in the first row, the table writes #line in the first row without writing the value next to it, as shown here:
With this we can use your snippet (replacing #top with #line) and this will be the result
It also solves the above mentioned sorting issue , as shown here:
And after modifying your snippet and adding some styling to it , this is the final result:
The Snippet
.theme-dark .grouped-levels table tbody:has(a[href^="#line"]) {
border: 1px solid rgba(49,50,68,255);
& td {
border-right: 1px solid rgba(49,50,68,255);
text-align: center;
vertical-align: middle;
padding: 10px;
}
& td:has(a[href^="#line"]) {
& a[href^="#line"] {
display: none;
}
border-top: 1px solid rgba(49,50,68,255);
}
}
.theme-dark .grouped-levels table thead th {
padding: 5px 10px;
background-color: #1B1A29 !important;
border-bottom: 1px solid #302D41;
border-top: 1px solid #302D41;
border-left: 1px solid #302D41;
border-right: 1px solid #302D41;
text-align: center;
color: #A79CB0;
font-size: 16px;
}
.theme-dark.grouped-levels td,
.theme-dark.grouped-levels th {
border: 1px solid #302D41;
padding: 4px 4px;
border-left: 1px solid #302D41;
border-right: 1px solid #302D41;
}
.theme-dark .grouped-levels table tbody td:nth-child(odd) {
background-color: #1E1E2E;
}
.theme-dark .grouped-levels table tbody td:nth-child(even) {
background-color: #1B1A29;
}
.theme-light .grouped-levels table tbody:has(a[href^="#line"]) {
border: 1px solid #BCC0CC;
& td {
border-right: 1px solid #BCC0CC;
text-align: center;
vertical-align: middle;
padding: 10px;
}
& td:has(a[href^="#line"]) {
& a[href^="#line"] {
display: none;
}
border-top: 1px solid #BCC0CC ;
}
}
.theme-light .grouped-levels table thead th {
padding: 5px 10px;
background-color: #E8ECF1 !important;
border-bottom: 1px solid #BCC0CC;
border-top: 1px solid #BCC0CC;
border-left: 1px solid #BCC0CC;
border-right: 1px solid #BCC0CC;
text-align: center;
color: #9599A9;
font-size: 16px;
}
.theme-light.grouped-levels td,
.theme-light.grouped-levels th {
border: 1px solid #BCC0CC;
padding: 4px 4px;
border-left: 1px solid #BCC0CC;
border-right: 1px solid #BCC0CC;
}
.theme-light .grouped-levels table tbody td:nth-child(odd) {
background-color: #EFF1F5;
}
.theme-light .grouped-levels table tbody td:nth-child(even) {
background-color: #E8ECF1;
}
The final output:
Edit : If anyone wants to hide the number beside level 1 (in this case section),
Add this to the snippet.
.dataview.small-text {
display: none;
}
Anyway, thanks for your great idea