How to customize the outline (table of contents) inside a table or grid?

I want to recreate this style of Table of content, Can anyone Guide me…
Outline function is hard to work with

This question was resolved over on the discord

This was accepted as the solution:

#let table-outline(title: upper[Table of Contents], depth: none) = context {
  let hs = query(heading)
  let rows = (table.header(
    ..([Sr. no.], [Topics], [Page no.])
      .map(strong).map(align.with(center))
  ),)

  for h in hs {
    if depth != none and h.level > depth { continue }
    if not h.outlined { continue }
    
    let disp(elem, numb) = numbering(numb, ..counter(elem).at(h.location()))

    let page = disp(page, h.location().page-numbering())
    let num = disp(heading, h.numbering)
    
    if h.level == 1 {
      rows.push(([#num.], [*_#h.body;_*], page))
    } else {
      rows.last().at(1) += [\ #num. #h.body]
      rows.last().at(2) += [\ #page]
    }
  }

  align(center, heading(numbering: none, outlined: false, title))
  
  table(
    stroke: .5pt,
    columns: (2cm, 1fr, 2cm),
    align: (center, left, center),
    ..rows.flatten()
  )
}

#table-outline()

#set page(numbering: "i")
#set heading(numbering: "i")

= Certificate
= Methodology
= Acknowledgements
= Preface
= Abstract

#set heading(numbering: "1.1")
#counter(heading).update(0)
#set page(numbering: "1")
#counter(page).update(1)

= Introduction
== Background
== Definition
== Purpose
== Chapter Scheme
= Leadership Theories
== Great Man Theory
== Trait Theory
== Contingency Theory
== Situational Theory
== Behavioral Theory
== Applying leadership theories at workplace
== Key Takeaways
= Leadership Styles
== Autocratic Leadership
== Laissez-Faire Leadership
== Democratic Leadership
== Transformational Leadership
== Transactional Leadership
= Leadership v/s Management
== What is a manager
== Key difference between a leader and a manager
= Data Analysis and Findings
= Conclusions

#set page(numbering: "I")
#counter(page).update(10)

= Recommendations
= Appendix
= List of References
= Glossary (if applicable)

Credit to @cAtte for the solution posted on Discord and copied here for the benefit of all forum users.

4 Likes