📄 Documentation: IrbyImaging/Views/JDE/Search.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. ViewModel & Data Flow
  4. Search Form 🔍
  5. Equipment TreeGrid 📊
  6. JavaScript & UI Interactions ⚙️
  7. Styling & Custom CSS 🎨
  8. API Endpoints Overview
  9. Usage Examples & Code Snippets
  10. UML Sequence Diagram
  11. Conclusion

1. Overview & Purpose

Search.cshtml is an ASP.NET Core Razor View designed to:

  • 🔍 Provide a search interface for equipment documents by various criteria (class, type, unit number, etc.).
  • 📊 Display search results in a rich, hierarchical TreeGrid (via Syncfusion EJ2) with filtering, sorting, paging, and export capabilities.
  • ⚙️ Enhance UX with cascading dropdowns, client‐side validation, and export handlers.

2. Dependencies & Technologies

Library / Framework Purpose
ASP.NET Core MVC (Razor) Server-side rendering & model binding
Syncfusion EJ2 (Syncfusion.EJ2) TreeGrid, Buttons, Export features
jQuery DOM manipulation, AJAX
Bootstrap 4/5 Responsive layout & form styling
Select2 Enhanced <select> dropdowns
TinyMCE Rich text editor (imported but not used here)
jquery.repeater Dynamic form‐section repeating
simplebar, waves Custom scrollbars & ripple effects
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@using Syncfusion.EJ2

3. ViewModel & Data Flow

@model IrbyImaging.UI.Models.Equipment
  • Input Model: Equipment

    • IEnumerable<SelectListItem> EquipmentClasses
    • IEnumerable<SelectListItem> EquipmentTypes
    • Other properties (Class, Type, UnitNumber, …) used for form‐binding.
  • Output Data:

    • ViewBag.Equipment holds a hierarchical collection of equipment details consumed by the TreeGrid.

4. Search Form 🔍

<form asp-action="Search" method="post" class="form-horizontal typeSearch" id="validation-form">
  @Html.AntiForgeryToken()
  @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  <!-- ... form fields ... -->
  <button type="submit" class="btn btn-primary">Search Documents</button>
</form>

4.1 Form Fields

Field Type Description
Equipment Class <select> Populated by Model.EquipmentClasses
Equipment Type <select> Populated dynamically on Class change
Unit Number <input> Free‐text
Job Number <input> Free‐text
Asset Number <input> Free‐text
Serial Number <input> Free‐text
Search History? <checkbox> Toggle to include historical data

4.2 Cascading Dropdown (Class → Type)

$("#Class").change(function () {
  var cls = $('#Class option:selected').text();
  $.ajax({
    url: "@Url.Action("GetTypes","JDE")",
    type: "POST",
    data: { clsName: cls },
    success: function (data) {
      var options = "<option value='0'>Select Equipment Type</option>";
      data.forEach(function(item) {
        options += `<option value='${item.Value}'>${item.Text}</option>`;
      });
      $("#Type").html(options);
    },
    error: function (res) {
      alert("Error loading types: " + res);
    }
  });
});

5. Equipment TreeGrid 📊

The lower section renders a Syncfusion EJ2 TreeGrid to display search results.

<ejs-treegrid id="TreeGrid"
  dataSource="ViewBag.Equipment"
  childMapping="Children"
  allowPaging="true" allowFiltering="true" allowSorting="true"
  toolbar="@(new List<string>{ "ExcelExport", "CsvExport", "PdfExport", "Print" })"
  ...
>
  <e-treegrid-pagesettings pageSize="10"></e-treegrid-pagesettings>
  <e-treegrid-filtersettings type="Excel"></e-treegrid-filtersettings>
  <e-treegrid-columns>
    <!-- Column definitions -->
  </e-treegrid-columns>
</ejs-treegrid>

5.1 Columns & Features

Field Header Text Type Notes
Name Name string Tree column
Job.JdeNumber Job# string Nested field
Job.Name JobName string Uses custom template
AssetNumber Asset# string
UnitTagNumber Unit# string
SerialNumber Serial# string
DateAcquired Date Acquired date Formatted MM/dd/yyyy on load
DateDisposed Date Disposed date
… … … …

Key Features

  • ✅ Filtering & Sorting per column
  • ✅ Paging (pageSize=10)
  • ✅ Reordering & Text Wrap
  • ✅ Excel / CSV / PDF / Print Export
  • ✅ Persist collapsed state (custom handler)

5.2 Toolbar & Export Handlers

function toolbarClick(args) {
  var treeGrid = document.getElementById("TreeGrid").ej2_instances[0];
  if (args.item.id.endsWith('_excelexport')) {
    treeGrid.excelExport({ isCollapsedStatePersist: collapsedStatePersist });
  } else if (args.item.id.endsWith('_pdfexport')) {
    treeGrid.pdfExport({ isCollapsedStatePersist: collapsedStatePersist });
  } else if (args.item.id.endsWith('_csvexport')) {
    treeGrid.csvExport();
  }
}
function onChange(args) {
  collapsedStatePersist = args.checked;
}

6. JavaScript & UI Interactions ⚙️

  1. Cascading Dropdown (Class → Type)
  2. TreeGrid load Event formats date columns:
    function load(args) {
      this.columns[6].format = { type: 'date', format: 'MM/dd/yyyy' };
      // ... similarly for other date columns ...
    }
    
  3. Client‐side Search on TreeGrid:
    document.getElementById('Search').addEventListener('click', function(){
      var val = document.getElementById('searchText').value;
      var grid = document.getElementById('TreeGrid').ej2_instances[0];
      grid.search(val);
    });
    
  4. Select2 Initialization for enhanced selects:
    $('.js-example-basic-single').select2();
    
  5. Form Repeater & TinyMCE (imported for other pages)

7. Styling & Custom CSS 🎨

#property td div.e-checkbox-wrapper {
  padding-left: 0 !important;
  padding-top: 0 !important;
}
  • Removes extra padding around Syncfusion checkboxes.

8. API Endpoints Overview

Endpoint HTTP Purpose
/JDE/Search GET Render initial search page
/JDE/Search POST Process filters, return updated view/model
/JDE/GetTypes POST Return JSON list of Equipment Types by Class

9. Usage Examples & Code Snippets

Controller (JDEController.cs)

public class JDEController : Controller
{
  [HttpGet]
  public IActionResult Search()
  {
    var model = new EquipmentViewModel {
      EquipmentClasses = _service.GetClasses(),
      EquipmentTypes   = new List<SelectListItem>()
    };
    ViewBag.Equipment = new List<EquipmentDto>();
    return View(model);
  }

  [HttpPost]
  [ValidateAntiForgeryToken]
  public IActionResult Search(EquipmentViewModel model)
  {
    ViewBag.Equipment = _service.FindEquipment(model);
    // repopulate dropdowns
    model.EquipmentClasses = _service.GetClasses();
    model.EquipmentTypes   = _service.GetTypes(model.Class);
    return View(model);
  }

  [HttpPost]
  public JsonResult GetTypes(string clsName)
  {
    var types = _service.GetTypes(clsName);
    return Json(types);
  }
}

10. UML Sequence Diagram

sequenceDiagram
    participant U as User
    participant V as Search.cshtml (View)
    participant C as JDEController
    participant D as Database/API

    U->>C: GET /JDE/Search
    C-->>U: Renders Search.cshtml with Model
    U->>V: Fill Form & Click "Search"
    V->>C: POST /JDE/Search (form data)
    C->>D: Query equipment by filters
    D-->>C: Returns equipment list
    C-->>V: Return view with ViewBag.Equipment
    V->>U: Display TreeGrid results

11. Conclusion

This Search.cshtml view empowers users to 🔍 filter and 📊 visualize equipment records in an intuitive, feature‑rich interface. Leveraging Syncfusion EJ2 for the TreeGrid, plus jQuery/AJAX for dynamic dropdowns, it demonstrates a balanced blend of server‑side rendering and client‑side interactivity. For further customization:

  • Extend column templates
  • Tweak export configurations
  • Integrate additional third‑party widgets

Happy coding! 🚀