📄 ShowAssetsByField.cshtml Documentation

Location: IrbyImaging/Views/ATSHome/ShowAssetsByField.cshtml
Purpose: Render an interactive, filterable, sortable & exportable grid of assets per Field Office using Syncfusion EJ2 controls in an ASP.NET MVC Razor view.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model Binding & Data Source
  4. Layout & Styling
  5. UI Components & Key Functional Areas
  6. Client-Side Scripts & Event Handlers
  7. UML Component Diagram
  8. Usage Example & Controller Integration
  9. Best Practices & Notes
  10. Conclusion

🔍 1. Overview & Purpose

This Razor view renders a Total Assets View for each Field Office, enabling users to:

  • 🔀 Sort, group and filter records
  • 📄 Export data to Excel or PDF
  • 🔍 Perform live text searches
  • ↕️ Drag & drop rows
  • 📦 Download a ZIP package of assets

All functionality is powered by Syncfusion EJ2 JavaScript components within an ASP.NET MVC framework.


🛠️ 2. Dependencies & Technologies

Layer Technology / Library
Server-Side ASP.NET MVC (Razor)
Client-Side Syncfusion EJ2 (Syncfusion.EJ2)
JavaScript Modules Syncfusion.JavaScript, Syncfusion.JavaScript.Models
Styling Bootstrap 4 (via _ATSLayout.cshtml), Custom CSS
Data Binding Razor @model, ViewBag.datasource

Note: Ensure Syncfusion EJ2 scripts & styles are referenced in the shared layout (_ATSLayout.cshtml).


👤 3. Model Binding & Data Source

@model IrbyImaging.UI.Models.AssetsView
@{
    ViewData["Title"] = "Assets List";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • Model: AssetsView — contains the view‑model data structure (e.g., IEnumerable<AssetDto>).
  • ViewBag: ViewBag.datasource — holds the raw data array for the grid.

Example Controller Setup

public class ATSHomeController : Controller
{
    public IActionResult ShowAssetsByField()
    {
        var viewModel = new AssetsView { /* populate properties */ };
        ViewBag.datasource = viewModel.AssetList;
        return View(viewModel);
    }

    [HttpGet]
    public FileResult DownloadZip()
    {
        byte[] zipBytes = ZipService.CreateFieldOfficeAssetsZip();
        return File(zipBytes, "application/zip", "Assets_By_FieldOffice.zip");
    }
}

🎨 4. Layout & Styling

Custom CSS is embedded at the top of the view to theme the Syncfusion grid:

<style>
  .e-grid .e-gridheader { border:2px solid black }
  .e-grid .e-headercell   { color: darkblue }
  .e-grid .e-sortnumber   { background-color: #deecf9; font-family: cursive }
  .e-grid .e-icon-ascending::before  { content: '\e306'; }
  .e-grid .e-icon-grightarrow::before{ content:'\e913'; }
  /* ... more stylings for grouping, expand/collapse, indent cells ... */
</style>

Tip: Move heavy styling into a dedicated CSS file under wwwroot/css/ for maintainability.


⚙️ 5. UI Components & Key Functional Areas

5.1 Header & Action Buttons

<div class="row mb-3">
  <div class="col-lg-2">
    <a asp-action="DownloadZip" class="btn btn-success irby-green">
      📥 Download Assets By Field Office
    </a>
  </div>
</div>
<h2>Total Assets View</h2>
  • Download Button: triggers the DownloadZip action, streams a ZIP package of asset attachments.
  • Clear Search Button: implemented via EJ2 <ejs-button> to reset grid search.

5.2 Syncfusion EJ2 Grid Configuration

<ejs-grid id="Grid"
          allowSorting="true"
          allowGrouping="true"
          allowFiltering="true"
          allowRowDragAndDrop="true"
          allowPaging="true"
          allowExcelExport="true"
          allowPdfExport="true"
          dataSource="@ViewBag.datasource"
          toolbar="@(new List<string>{"ExcelExport","PdfExport","Search"})"
          toolbarClick="toolbarClick">
    <e-grid-filterSettings type="Excel"></e-grid-filterSettings>
    <e-grid-editSettings allowAdding="true"
                         allowEditing="true"
                         allowDeleting="true"
                         edit-mode="@(EditMode.Normal)">
    </e-grid-editSettings>
    <!-- Columns declared below -->
</ejs-grid>
Property Description
allowSorting Enable column-wise sorting
allowGrouping Enable grouping by columns
allowFiltering Display Excel-like filter menus
allowRowDragAndDrop Reorder rows by drag-and-drop
allowPaging Paginate data
allowExcelExport Expose Excel export in toolbar
allowPdfExport Expose PDF export in toolbar
toolbar Array of built-in toolbar items
toolbarClick JS handler for toolbar button clicks
dataSource Bound to ViewBag.datasource

5.3 Grid Columns Definition

Field Header Text Width Alignment Format Notes
FieldOfficeNumber FieldOffice# 70 Center — isPrimaryKey
FieldOfficeName FieldOfficeName 110 — —
JobNumber Job# 70 Center — isPrimaryKey
JobName Job Name 110 — —
EmployeeNumber AssignedTo# 70 Center — isPrimaryKey
EmploymentStatus Employment Status 75 Center —
TerminationDate Termination Date 110 Center MM/dd/yyyy Date formatting
EmployeeName Employee Name 110 — —
Type Asset Type 70 Left —
Category Category 75 Left —
ModelName Model 110 — —
PhoneNumber Phone# 80 Center —
AssetNumber Asset# 110 Center —
SerialNumber Serial# 110 — —
Status Asset Status 75 Center —
IsTelogis Is Telogis 70 — — Boolean flag

🖥️ 6. Client-Side Scripts & Event Handlers

<script>
  // Clear the search input on button click
  document.getElementById('clear')
          .addEventListener('click', () => {
    let gridObj = document.getElementById("Grid").ej2_instances[0];
    gridObj.searchSettings.key = '';
  });

  // Toolbar click handler for export
  function toolbarClick(args) {
    let gridObj = document.getElementById("Grid").ej2_instances[0];
    if (args.item.id === 'Grid_excelexport') {
      gridObj.excelExport();
    }
    if (args.item.id === 'Grid_pdfexport') {
      gridObj.pdfExport();
    }
  }
</script>
  • clear button: Resets the EJ2 Grid search key.
  • toolbarClick function: Invokes .excelExport() or .pdfExport() based on the clicked toolbar item.

Caution: Ensure one toolbarClick function; merging both checks avoids function overrides.


📊 7. UML Component Diagram

flowchart TB
    subgraph MVC Architecture
      C[Controller: ATSHomeController] -->|Passes Data| V[View: ShowAssetsByField.cshtml]
      V -->|Renders| U[User Browser]
      V -->|Calls| S[Syncfusion EJ2 Grid]
      U -->|Clicks “Download”| C
      S -->|Toolbar Events| JS[Client Script]
    end
  • Controller prepares data & returns the view
  • View leverages Syncfusion EJ2 for rendering
  • Client Script handles interactions (search clear, exports)

🔗 8. Usage Example & Controller Integration

  1. Route: /ATSHome/ShowAssetsByField

  2. Controller Action:

    public IActionResult ShowAssetsByField()
    {
        // Fetch or compute assets grouped by field office
        var assets = _assetService.GetAllAssetsByFieldOffice();
        ViewBag.datasource = assets;
        return View();
    }
    
  3. Browser Behavior:

    • Page loads with a dynamic EJ2 grid
    • User can sort, group, filter, page, search
    • Click 📥 Download Assets By Field Office → downloads a ZIP file
    • Use toolbar to export Excel or PDF

✅ 9. Best Practices & Notes

  • Single toolbarClick: Combine export conditions to prevent JS override.
  • Move CSS out: For large styles, create a dedicated CSS file.
  • Strongly‑typed Data: Consider using @model and Model.Assets instead of ViewBag.
  • Performance: For very large data sets, enable server‑side paging/filtering.
  • Accessibility: Add aria-labels to buttons and grid for screen readers.

🎯 10. Conclusion

This ShowAssetsByField view delivers an efficient, user-friendly interface for asset management per Field Office. Leveraging Syncfusion EJ2, it provides advanced grid features—sorting, filtering, grouping, export—while maintaining a clean Razor layout. Properly integrating server‑side data and client scripts ensures a seamless UX for end users.

Happy coding! 🚀