🗂️ Documentation: IrbyImaging/Views/Jobs/Index.cshtml


📖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. File Structure & Key Sections
  4. View Models & Data Models
  5. Helper Methods & Utilities
  6. Event Handling & APIs
  7. Third‑Party Integrations
  8. Usage Examples
  9. UML Diagrams
  10. Conclusion

🧐 1. Overview & Purpose

Index.cshtml is a Razor view in the IrbyImaging solution that renders a dynamic, interactive Job List. It leverages Syncfusion’s EJ2 TreeGrid to display hierarchical job data, complete with:

  • 🔍 Search by keyword
  • 📊 Sorting, Filtering, Paging
  • 📑 Export to Excel/CSV/PDF & Print
  • 🌐 Nested/Child rows (via Children property)

This view is typically returned by JobsController.Index and expects a model of IEnumerable<IrbyImaging.DomainClasses.Job> plus ViewBag.Jobs for the grid’s data source.


⚙️ 2. Dependencies & Technologies

Category Details
Framework ASP.NET Core MVC, Razor Views
UI Library Syncfusion EJ2 (TreeGrid, Buttons)
Styling Bootstrap 4 (cards, badges, form-inline)
JavaScript ES6, Syncfusion EJ2 scripts
Markup HTML5, Razor syntax
Server-side C# Domain Model: IrbyImaging.DomainClasses.Job

📝 3. File Structure & Key Sections

Views/
└── Jobs/
    └── Index.cshtml  ← This file

3.1. Razor Pre‑Processing

@model IEnumerable<IrbyImaging.DomainClasses.Job>
@{
    ViewData["Title"] = "Job List";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • @model: Strongly‑typed view using a collection of Job.
  • ViewData["Title"]: Sets browser tab & header title.
  • Layout: Inherits shared _ATSLayout.cshtml.

3.2. Header & Title

<h2>
  Jobs 
  <span class="badge badge-info" style="color: #11467e">
    @Model.Count()
  </span>
</h2>
  • Heading: Displays “Jobs” and a Bootstrap badge with the total count.
  • @Model.Count(): Real‑time job count.

3.3. Search UI

<div class="row">
  <div class="form-inline col-lg-offset-10 col-lg-2">
    <form asp-action="Index" method="get">
      <!-- Optional server-side search (commented out) -->
    </form>
  </div>
</div>
  • Placeholder for server-side search via <form>.
  • Implements client-side search with an <input> + Syncfusion <ejs-button> later in the grid region.

3.4. TreeGrid Component

🚀 Core of this view:

<ejs-treegrid
  id="TreeGrid"
  dataSource="ViewBag.Jobs"
  childMapping="Children"
  treeColumnIndex="0"
  allowReordering="true"
  allowFiltering="true"
  allowSorting="true"
  allowTextWrap="true"
  allowPaging="true"
  allowExcelExport="true"
  allowPdfExport="true"
  toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport", "Print" })"
  width="100%"
  height="100%"
>
  <e-treegrid-pagesettings pageSize="10"></e-treegrid-pagesettings>
  <e-treegrid-filtersettings type="Excel"></e-treegrid-filtersettings>
  <e-treegrid-columns>
    <!-- Column definitions: JdeNumber, Name, JobType, …, GeoRegionCode -->
  </e-treegrid-columns>
</ejs-treegrid>

Highlights

  • dataSource: Binds to ViewBag.Jobs JSON data.
  • childMapping: Uses the Children property for hierarchical rows.
  • Toolbar: Excel/CSV/PDF/Print buttons.
  • Columns: Configured with sorting/filtering, widths, templates.

3.5. Custom Templates

<script id="fldtemplate" type="text/x-template">
  <div class="image" id="edit">
    <a target="_blank" href="/FieldOffices/Details/${FieldOfficeId}">
      ${FieldOffice}
    </a>
  </div>
</script>
  • FieldOffice column uses a template (#fldtemplate) to render clickable links.

3.6. Styles & Layout

<style>
  #property td div.e-checkbox-wrapper {
    padding-left: 0 !important;
    padding-top: 0 !important;
  }
</style>
  • Minor CSS tweak to align checkboxes inside table cells.

3.7. Scripts & Behaviors

<script>
  // 1️⃣ Format date columns on grid load
  function load(args) {
    ["DateActualStart","DateActualComplete","DatePlannedStart","DatePlannedComplete"]
      .forEach((f,i) => this.columns[11 + i].format = { type: 'date', format: 'MM/dd/yyyy' });
  }

  // 2️⃣ Client-side search button
  document.getElementById('Search').addEventListener('click', function () {
    const val = document.getElementById('searchText').value;
    const treegrid = document.getElementById('TreeGrid').ej2_instances[0];
    treegrid.search(val);
  });

  // 3️⃣ Toolbar click handler for export persistence
  var collapsedStatePersist = true;
  function toolbarClick(args) { /* Excel/PDF/CSV export logic */ }
  function onChange(args) { collapsedStatePersist = args.checked; }
</script>
  • load: Applies date formatting to specific columns.
  • Search: Binds the Search button to treegrid.search(...).
  • toolbarClick/onChange: Manage export behavior and state persistence.

📦 4. View Models & Data Models

namespace IrbyImaging.DomainClasses
{
  public class Job
  {
    public int JdeNumber { get; set; }
    public string Name { get; set; }
    public string JobType { get; set; }
    public string ContractType { get; set; }
    public string WorkType { get; set; }
    public string Customer { get; set; }
    public string FieldOffice { get; set; }
    public int FieldOfficeId { get; set; }
    public string Manager { get; set; }
    public string Superintendent { get; set; }
    public string ProjectEstimator { get; set; }
    public string JobStatus { get; set; }
    public DateTime DateActualStart { get; set; }
    public DateTime DateActualComplete { get; set; }
    public DateTime DatePlannedStart { get; set; }
    public DateTime DatePlannedComplete { get; set; }
    public decimal RevenueDerivative { get; set; }
    public string GeoRegionCode { get; set; }
    public List<Job> Children { get; set; }
  }
}
  • IEnumerable passed as the view’s model for header count.
  • ViewBag.Jobs holds the same or nested JSON data for the TreeGrid.

🛠️ 5. Helper Methods & Utilities

  • load(args): Formats date columns when the grid is initialized.
  • toolbarClick(args): Customizes Excel/PDF/CSV export with collapsed-state persistence.
  • onChange(args): Toggles collapsedStatePersist flag.

🔄 6. Event Handling & APIs

  • GET /Jobs/Index

    • Returns this Razor view.
    • Populates Model: IEnumerable<Job> and ViewBag.Jobs (JSON-serializable).
  • Client‑side

    • Search → treegrid.search(val)
    • Exports → excelExport(), pdfExport(), csvExport()

🔌 7. Third‑Party Integrations

Library Purpose
Syncfusion EJ2 TreeGrid, Buttons, Export, Filtering, etc.
Bootstrap 4 Layout, badges, forms, cards
jQuery (optional) Legacy support (not required here)

💡 8. Usage Examples

8.1. Injecting the View from Controller

public class JobsController : Controller
{
    public IActionResult Index()
    {
        var jobs = _jobService.GetAllJobsHierarchy();  // returns List<Job>
        ViewBag.Jobs = JsonConvert.SerializeObject(jobs);
        return View(jobs);
    }
}

8.2. Customizing a Column

<e-treegrid-column
  field="Manager"
  headerText="Project Manager"
  width="180"
  allowFiltering="true"
  allowSorting="true"
  template="<span style='font-weight:bold;'>${Manager}</span>">
</e-treegrid-column>

📊 9. UML Diagrams

9.1. Class Diagram (Job)

classDiagram
  class Job {
    +int JdeNumber
    +string Name
    +string JobType
    +string ContractType
    +string WorkType
    +string Customer
    +string FieldOffice
    +int FieldOfficeId
    +string Manager
    +string Superintendent
    +string ProjectEstimator
    +string JobStatus
    +DateTime DateActualStart
    +DateTime DateActualComplete
    +DateTime DatePlannedStart
    +DateTime DatePlannedComplete
    +decimal RevenueDerivative
    +string GeoRegionCode
    +List~Job~ Children
  }

9.2. Sequence Diagram (Search Flow)

sequenceDiagram
  participant U as User
  participant D as DOM
  participant T as TreeGrid

  U->>D: Click “Search” 🔍  
  D->>D: onClick handler reads input  
  D->>T: treeGrid.search(value)  
  T->>T: Applies filter  
  T->>U: Renders filtered rows  

🏁 10. Conclusion

Index.cshtml delivers a powerful, interactive Job List UI with minimal code overhead by leveraging Syncfusion EJ2 TreeGrid. Developers can easily:

  • Extend columns & templates
  • Hook into grid events
  • Customize export behaviors
  • Maintain hierarchical data

Feel free to adapt the load, toolbarClick, and template scripts to meet your project’s specific requirements! 🚀