Equipment Directory View (EquipmentDirectory.cshtml) π
Location:
IrbyImaging/Views/JDE/EquipmentDirectory.cshtml
Responsibilities:
- Render a search form for equipment
- Display equipment in a hierarchical TreeGrid
- Handle clientβside events (filtering, sorting, exporting)
- Perform AJAX calls to populate dependent dropdowns
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies π οΈ
- View Model & Data Model π§©
- Helper Methods & Utilities π§°
- Error Handling & Validation β οΈ
- API Endpoints & AJAX Calls π
- Third-Party Integrations π
- Sample Code Blocks π»
- Usage Examples π―
- UML Sequence Diagram π
- Conclusion β
1. Overview & Purpose
This Razor view renders a search interface and a Syncfusion EJ2 TreeGrid for viewing and managing equipment records.
- Search Form
- Allows users to filter by class/type, unit number, job number, asset number, serial number, and history flag.
- TreeGrid
- Displays hierarchical equipment data (parent/child relationships)
- Supports paging, sorting, filtering, exporting (Excel/PDF) and live search
2. Key Functional Areas
2.1 Search Form π
Purpose: Collect filter criteria and post them to the Search action of the JDE controller.
<form asp-action="Search" method="post" id="validation-form" class="form-horizontal typeSearch">
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="row">
<div class="col-lg-12 card">
<div class="card-body">
<h4 class="card-title mb-4">View Equipment</h4>
<div data-repeater-list="outer-group" class="outer">
<div data-repeater-item class="outer">
<!-- Equipment Class & Type -->
<div class="form-group row mb-2">
<label class="col-lg-2 col-form-label">Equipment Class</label>
<div class="col-md-4">
<select asp-for="Class" asp-items="@Model.EquipmentClasses"
id="Class" class="form-control">
<option value="" disabled selected>Select Equipment Class</option>
</select>
</div>
<label class="col-lg-2 col-form-label">Equipment Type</label>
<div class="col-md-4">
<select asp-for="Type" asp-items="@Model.EquipmentTypes"
id="Type" class="form-control">
<option value="" disabled selected>Select Equipment Type</option>
</select>
</div>
</div>
<!-- ... other fields ... -->
</div>
</div>
<button type="submit" class="btn btn-primary">Search Equipment</button>
</div>
</div>
</div>
</form>
Highlights:
- Uses ASP.NET Tag Helpers (
asp-for,asp-items) - Repeater markup (
data-repeater-list,data-repeater-item) for dynamic groups - Standard Bootstrap grid for responsive layout
2.2 Equipment List Grid π
Utilizes Syncfusion EJ2 TreeGrid to display hierarchical equipment data:
<ejs-grid id="TreeGrid"
load="load"
dataSource="ViewBag.Equipment"
childMapping="Children"
treeColumnIndex="0"
allowPaging="true" allowSorting="true"
allowFiltering="true" allowReordering="true"
allowResizing="true" allowMultiSorting="true"
allowTextWrap="true"
frozenColumns="3"
allowPdfExport="true" allowExcelExport="true"
toolbar="@(new List<string>() { "ExcelExport", "PdfExport"})">
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-grid-filtersettings type="Excel"></e-grid-filtersettings>
<e-grid-columns>
<e-grid-column field="Name" headerText="Name" width="150"></e-grid-column>
<e-grid-column field="AssetNumber" headerText="Asset#" width="220"></e-grid-column>
<!-- ... additional columns ... -->
</e-grid-columns>
</ejs-grid>
Key Features:
- Hierarchical (
childMapping="Children") - Frozen columns for persistent context
- Extensive client-side features: sorting, filtering, paging, exporting
2.3 Templates & Styling π¨
- Job Name Template
<script id="jobtemplate" type="text/x-template"> <a target="_blank" href="/Jobs/Details/${JobId}">${Job.Name}</a> </script> - Custom Styles
#property td div.e-checkbox-wrapper { padding-left: 0 !important; padding-top: 0 !important; }
2.4 Scripts & Events βοΈ
| Script/Function | Purpose |
|---|---|
load(args) |
Format date columns on grid initialization |
dataBound(args) |
Auto-fit columns after data bind |
toolbarClick(args) |
Handle Excel/PDF export from toolbar |
#Class change AJAX call |
Populate EquipmentType dropdown based on selected class |
#Search click |
Trigger client-side search on the TreeGrid |
// Populate Types when a Class is selected
$("#Class").change(function() {
$.ajax({
url: "@Url.Action("GetTypes","JDE")",
type: "POST",
data: { clsName: $('#Class').val() },
success: function(data) {
// build <option> list...
},
error: function(resp) { alert("Error: " + resp); }
});
});
3. Dependencies & Technologies π οΈ
| Technology | Usage |
|---|---|
| ASP.NET Core MVC (Razor) | View rendering, Tag Helpers |
| Syncfusion EJ2 TreeGrid | Hierarchical data grid |
| jQuery | DOM manipulation, AJAX |
| Bootstrap 4/5 | Grid layout, form styling |
| Select2 | Enhanced <select> |
| AJAX | Populate dropdown, partial updates |
| Spin.js | Loading spinners (script included) |
4. View Model & Data Model π§©
View Model: IrbyImaging.UI.Models.Equipment
| Property | Type | Description |
|---|---|---|
Class |
string |
Selected equipment class |
Type |
string |
Selected equipment type |
UnitNumber |
string |
Unit Identifier |
JobNumber |
string |
Linked Job Identifier (JDE Number) |
AssetNumber |
string |
Asset Order Number |
SerialNumber |
string |
Equipment Serial Number |
SearchHistory |
bool |
Include historical records? |
EquipmentClasses |
IEnumerable<SelectListItem> |
Dropdown options for classes |
EquipmentTypes |
IEnumerable<SelectListItem> |
Dropdown options for types |
Data Model (Grid item):
public class EquipmentDto {
public string Name { get; set; }
public string AssetNumber { get; set; }
public string UnitTagNumber { get; set; }
public JobDto Job { get; set; }
public string SerialNumber { get; set; }
public DateTime? DateAcquired { get; set; }
public DateTime? DateDisposed { get; set; }
public string Description { get; set; }
public string Status { get; set; }
public string FianceMethod { get; set; }
public string Class { get; set; }
public string FuelType { get; set; }
public decimal? Price { get; set; }
public string Manufacturer { get; set; }
public string CurrentStatus { get; set; }
public DateTime? BeginDate { get; set; }
public DateTime? EndDate { get; set; }
public List<EquipmentDto> Children { get; set; }
}
5. Helper Methods & Utilities π§°
load(args): Formats date columns after TreeGrid initialization.dataBound(args): CallsautoFitColumnsto adjust column widths dynamically.toolbarClick(args): InvokesexcelExport()orpdfExport()based on the clicked toolbar item.- AJAX wrapper: Simplifies populating dependent dropdowns.
6. Error Handling & Validation β οΈ
- Server-side validation with
@Html.ValidationSummary - Client-side form validation via
_ValidationScriptsPartial - AJAX error handlers display alerts on failure
- Select2 initialization wrapped in
$(document).ready
7. API Endpoints & AJAX Calls π
| Endpoint | Method | Parameters | Returns |
|---|---|---|---|
JDE/Search |
POST | Equipment model |
Redirects or re-renders view |
JDE/GetTypes |
POST | clsName (string) |
List<SelectListItem> JSON |
/Jobs/Details/{id} (link) |
GET | JobId (in URL) | Job detail page |
8. Third-Party Integrations π
- Syncfusion EJ2: Robust, enterprise-grade grid component
- Select2: Searchable dropdowns
- Spin.js: Loading indicators
- TinyMCE: Rich text editor (initialized but not shown directly)
9. Sample Code Blocks π»
9.1 AutoβFit Columns on Data Bound
function dataBound(args) {
this.autoFitColumns([
'Name','AssetNumber','UnitTagNumber','Job.JdeNumber','Job.Name',
'SerialNumber','DateAcquired','DateDisposed','Description','Status',
'FianceMethod','Class','FuelType','Price','Manufacturer',
'CurrentStatus','BeginDate','EndDate'
]);
}
9.2 Toolbar Export Handler
function toolbarClick(args) {
var grid = document.getElementById("TreeGrid").ej2_instances[0];
if (args.item.id === 'TreeGrid_pdfexport') {
grid.pdfExport();
} else if (args.item.id === 'TreeGrid_excelexport') {
grid.excelExport();
}
}
10. Usage Examples π―
-
Basic Search
- Select Equipment Class
- Choose Equipment Type (populated via AJAX)
- Enter
Unit Number,Job Number, etc. - Click Search Equipment
-
Live Grid Search
- Type text in the Search box (top-right)
- Click Search button β filters grid in real-time
-
Exporting Data
- Use grid toolbar:
- Excel Export
- PDF Export
- Use grid toolbar:
11. UML Sequence Diagram π
sequenceDiagram
participant U as User
participant V as EquipmentDirectory View
participant C as JDEController
participant G as Syncfusion TreeGrid
U->>V: Page Load
V->>G: Initialize TreeGrid(ViewBag.Equipment)
G-->>U: Render hierarchical grid
U->>V: Change Class dropdown
V->>C: POST GetTypes(clsName)
C-->>V: Return JSON List<SelectListItem>
V->>V: Populate Type dropdown
U->>V: Fill form & click Search
V->>C: POST Search(Equipment model)
C-->>V: Returns View with updated ViewBag.Equipment
V->>G: Refresh dataSource
U->>G: Click Export Toolbar
G->>G: ExcelExport() / PDFExport()
12. Conclusion β
This Equipment Directory view is a feature-rich interface for searching and viewing equipment records in a hierarchical grid. Leveraging Syncfusion EJ2, AJAX, Select2, and ASP.NET Core tag helpers, it provides a smooth user experience:
- Dynamic filters (class β type)
- Advanced grid features (sorting, filtering, paging, exporting)
- Responsive design with Bootstrap
- Robust validation (client & server)
By following the patterns shown above, you can extend or integrate this view to other modules (e.g., Parts Directory, Employee Directory) with minimal effort. Enjoy building! π