πŸ“„ DocumentCategories.cshtml Documentation

Welcome to the in-depth documentation for IrbyImaging/Views/HRImaging/DocumentCategories.cshtml. This Razor view renders and manages the Document Categories page in the HR Imaging module. It leverages Syncfusion EJ2 TreeGrid, jQuery AJAX, Bootstrap modals, and other libraries to provide a rich, interactive UI for viewing, filtering, exporting, and managing hierarchical document categories.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Model
  4. Layout & Razor Directives
  5. Key Functional Areas
  6. JavaScript Event Handlers & Utilities
  7. Third-Party Integrations
  8. Sample Code Blocks & Usage Examples
  9. UML Diagram
  10. Conclusion

πŸ“Œ Overview & Purpose

This view renders an interactive TreeGrid listing all document categories, along with actions to:

  • Add a new category
  • Search within categories
  • View Types under each category
  • Edit or Delete categories
  • Export data as Excel, CSV, PDF, or Print

It is part of the HR Imaging area under the IrbyImaging application and uses a strongly-typed DocumentCategoryView model.


πŸ”§ Dependencies & Technologies

Technology / Library Purpose
ASP.NET MVC / Razor Server-side rendering & templating
C# (DocumentCategoryView model) Strongly-typed view data
Syncfusion EJ2 TreeGrid Hierarchical grid UI
jQuery (v3.5.1) DOM manipulation & AJAX
DataTables (+ Buttons) (Scripts included for export features)
Bootstrap (Bundle) Layout, grid system, modal dialogs
MetisMenu Sidebar menu management
Simplebar Custom scrollbars
Node-Waves UI ripple effects

πŸ—‚ View Model & Data Model

namespace IrbyImaging.UI.Models
{
    public class DocumentCategoryView
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<string> TypeList { get; set; }
        public bool IsAvailable { get; set; }
        public bool IsDeleted { get; set; }
        public string AddedBy { get; set; }
        public DateTime AddedDate { get; set; }
        public string ModifiedBy { get; set; }
        public DateTime ModifiedDate { get; set; }

        // Hierarchical children for nested categories
        public List<DocumentCategoryView> Children { get; set; }
    }
}
  • Id: Unique identifier
  • Name: Category name
  • TypeList: List of associated document types
  • Children: Enables nested/hierarchical categories

πŸ— Layout & Razor Directives

@model IrbyImaging.UI.Models.DocumentCategoryView
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models

@{
    ViewBag.Title = "Document Categories";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
  • @model: Binds the view to DocumentCategoryView.
  • ViewBag: Defines page titles.
  • Layout: Uses the shared master layout.

πŸ”‘ Key Functional Areas

1. Syncfusion TreeGrid Configuration

<ejs-treegrid id="TreeGrid"
    dataSource="ViewBag.dataSource"
    childMapping="Children"
    treeColumnIndex="0"
    allowFiltering="true"
    allowSorting="true"
    allowPaging="true"
    allowExcelExport="true"
    allowPdfExport="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>
        <e-treegrid-column field="Name" headerText="Name" width="220"></e-treegrid-column>
        <e-treegrid-column field="TypeList" headerText="Type List" template="#typetemplate" width="150"></e-treegrid-column>
        <e-treegrid-column field="IsAvailable" headerText="Is Available"></e-treegrid-column>
        <e-treegrid-column field="IsDeleted" headerText="Is Deleted"></e-treegrid-column>
        <e-treegrid-column field="AddedBy" headerText="Added By"></e-treegrid-column>
        <e-treegrid-column field="AddedDate" headerText="Added Date"></e-treegrid-column>
        <e-treegrid-column field="ModifiedBy" headerText="Modified By"></e-treegrid-column>
        <e-treegrid-column field="ModifiedDate" headerText="Modified Date"></e-treegrid-column>
        <e-treegrid-column field="Edit" headerText="Edit/Update" template="#edittemplate"></e-treegrid-column>
        <e-treegrid-column field="Delete" headerText="Delete" template="#deletetemplate"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
  • dataSource: Populated from ViewBag.dataSource (set in controller).
  • childMapping="Children": Defines child nodes for hierarchical display.
  • Features: Filtering, sorting, paging, reordering, wrap, export.

2. Custom Templates (Edit / Delete / View Types)

<script id="edittemplate" type="text/x-template">
  <a target="_blank" href="/HRImaging/EditCategory/${Id}">Edit</a>
</script>

<script id="deletetemplate" type="text/x-template">
  <a href="/HRImaging/DeleteCategory/${Id}">Delete</a>
</script>

<script id="typetemplate" type="text/x-template">
  <a href="javascript:void(0);" class="anchorDetail" data-id=${Id}>View Types</a>
</script>
  • Edit: Opens the edit category page in a new tab.
  • Delete: Navigates to delete confirmation.
  • View Types: Triggers AJAX to show types in a modal.

3. Search & Toolbar Actions

  • Search πŸ“–:

    <input type="text" id="searchText" />
    <ejs-button id="Search" content="Search" cssClass="e-primary"></ejs-button>
    
    • On click, calls Syncfusion’s built-in search() API.
  • Toolbar Export Buttons πŸš€: Excel, CSV, PDF, Print are wired via toolbarClick event.


πŸ›  JavaScript Event Handlers & Utilities

var TeamDetailPostBackURL = '/HRImaging/myModalCategory';

$(function () {
  $(".anchorDetail").click(function () {
    var id = $(this).data('id');
    $.ajax({
      type: "GET",
      url: TeamDetailPostBackURL,
      data: { id: id },
      success: function (data) {
        $('#myModalContent').html(data);
        $('#myModal').modal('show');
      },
      error: function () {
        alert("Dynamic content load failed.");
      }
    });
  });
});
  • URL: /HRImaging/myModalCategory?id={Id}
  • Success: Loads partial view into Bootstrap modal.

Export (Excel, CSV, PDF, Print)

var collapsedStatePersist = true;

function toolbarClick(args) {
  var treeGridObj = document.getElementById("TreeGrid").ej2_instances[0];

  if (args.item.id.endsWith('_excelexport')) {
    treeGridObj.excelExport({ isCollapsedStatePersist: collapsedStatePersist });
  }
  else if (args.item.id.endsWith('_pdfexport')) {
    treeGridObj.pdfExport({ isCollapsedStatePersist: collapsedStatePersist });
  }
  else if (args.item.id.endsWith('_csvexport')) {
    treeGridObj.csvExport();
  }
}
  • collapsedStatePersist: Controls expansion state retention across exports.

Date Formatting on Load

function load() {
  var grid = document.getElementById("TreeGrid").ej2_instances[0];
  grid.columns.forEach(col => {
    if (col.field === "AddedDate" || col.field === "ModifiedDate") {
      col.format = { type: 'date', format: 'M/d/yyyy' };
    }
  });
}
  • Applies a MM/dd/yyyy format to date columns upon data load.

Grid Lines & Collapse Persistence

Two handlers share the same name onChange (beware of override!):

  1. Toggle collapse state persistence
    function onChange(args) {
      collapsedStatePersist = args.checked;
    }
    
  2. Toggle grid lines style
    function onChange(e) {
      var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
      treegrid.gridLines = e.value;
    }
    

πŸ”— Third-Party Integrations

  • Syncfusion EJ2: <ejs-treegrid>, <ejs-button>.
  • jQuery & DataTables: Scripts loaded for advanced table exports.
  • Bootstrap: Modal, layout, responsive grid.
  • MetisMenu / Simplebar / Node-Waves: UI enhancements.

πŸ’‘ Sample Code Blocks & Usage Examples

Adding a New Category

<a asp-action="CreateCategory" class="btn btn-success irby-green">
  Add New Document Category
</a>

Invoking Excel Export

// Trigger via toolbar button
treeGridObj.excelExport({
  isCollapsedStatePersist: true
});

Search Implementation

document.getElementById('Search').addEventListener('click', function () {
  var val = document.getElementById('searchText').value;
  var treegrid = document.getElementById('TreeGrid').ej2_instances[0];
  treegrid.search(val);
});

πŸ“ UML Diagram

@startuml
class DocumentCategoryView {
  +int Id
  +string Name
  +List<string> TypeList
  +bool IsAvailable
  +bool IsDeleted
  +string AddedBy
  +DateTime AddedDate
  +string ModifiedBy
  +DateTime ModifiedDate
  +List<DocumentCategoryView> Children
}

DocumentCategoryView "1" *-- "0..*" DocumentCategoryView : Children
@enduml

βœ… Conclusion

This view provides a robust, feature-rich interface to manage hierarchical document categories:

  • Full CRUD capabilities (Create, Read/View, Update, Delete)
  • Dynamic modal detail views
  • Powerful Syncfusion TreeGrid for filtering, sorting, paging
  • Multiple export formats with state persistence
  • Responsive & extensible via standard JS hooks

πŸš€ By following the structure above, you can effectively maintain or extend DocumentCategories.cshtml for additional features like custom column templates, advanced filtering, or integration with other modules.