📑 Document Attributes View Documentation
Welcome to the comprehensive documentation for the DocumentAttributes.cshtml Razor View in the IrbyImaging project. This file renders the Index Types page under the HRImaging module, providing a feature-rich interface to manage document attribute types using Syncfusion’s TreeGrid, modals, AJAX, and export tools.
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- File Structure & Razor Directives
- Page Layout & Titles
- Syncfusion TreeGrid Configuration
- Search, Toolbar & Export Functions
- Custom Templates & Columns
- Modal Dialog & AJAX Loading
- JavaScript Event Handlers & Utilities
- UML Class Diagram
- Usage Example
- Conclusion
1. ⭐ Overview & Purpose
The DocumentAttributes.cshtml view displays and manages Index Types (document attribute definitions) in a hierarchical grid. Key features include:
- Display: A tree-structured grid of attribute types with parent/child relationships.
- CRUD Actions: Buttons for Edit, Delete, and a global Add New action.
- Search: Quick full-text search across grid fields.
- Export: Export to Excel, CSV, PDF, and Print.
- Modal: View detailed children or related types in a pop-up dialog.
- Styling & Layout: Uses project’s shared layout (
_Layout.cshtml) and Bootstrap grid.
2. 🛠️ Dependencies & Technologies
| Category | Library / Framework | Purpose |
|---|---|---|
| Front-end Framework | Syncfusion EJ2 TreeGrid (Syncfusion.EJ2) |
Advanced grid with hierarchical data support |
| JavaScript Utils | jQuery 3.6 | DOM manipulation & AJAX |
| Data Export | DataTables & Buttons, JSZip, pdfmake | Alternate table exports (unused in TreeGrid) |
| UI & Layout | Bootstrap 5 | Responsive grid & modal dialogs |
| Menu & Scroll | MetisMenu, SimpleBar, Node-Waves | Sidebar menus & custom scroll |
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
3. 🗂️ File Structure & Razor Directives
@model IrbyImaging.UI.Models.DocumentAttributeView
@{
ViewBag.Title = "Index Types";
ViewBag.pTitle = "Index Types";
ViewBag.pageTitle = "Index Types";
Layout = "~/Views/Shared/_Layout.cshtml";
}
- @model: Strongly-typed to
DocumentAttributeView. - ViewBag: Sets page titles.
- Layout: Inherits the shared site layout.
4. 📐 Page Layout & Titles
<h2>Index Types</h2>
<div class="row">
<div class="col-lg-2">
<a asp-action="CreateAttribute" class="btn btn-success irby-green">
Add New Index Type
</a>
</div>
<!-- ...TreeGrid container... -->
</div>
- Header:
<h2>for page heading. - “Add New” Button: Links to
CreateAttributeaction inHRImagingcontroller.
5. 🌳 Syncfusion TreeGrid Configuration
The core component is Syncfusion’s TreeGrid, configured to display hierarchical attribute data.
<ejs-treegrid id="TreeGrid"
load="load"
dataSource="ViewBag.dataSource"
childMapping="Children"
showColumnMenu="true"
allowReordering="true"
allowFiltering="true"
allowSorting="true"
allowTextWrap="true"
allowPaging="true"
width="auto"
height="100%"
toolbarClick="toolbarClick"
allowExcelExport="true"
allowPdfExport="true"
toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport", "Print"})"
gridLines="Both"
>
<e-treegrid-pagesettings pageSize="10" />
<e-treegrid-filtersettings type="Excel" />
<e-treegrid-columns>
<!-- Columns defined in next section -->
</e-treegrid-columns>
</ejs-treegrid>
Key attributes:
- dataSource: Bound to
ViewBag.dataSource(populated by controller). - childMapping: Field name
"Children"for nested items. - Toolbar: Enables export and print.
- Events:
- load: Called on initialization to format date columns.
- toolbarClick: Handles export operations.
6. 🔍 Search, Toolbar & Export Functions
Search Box
<input type="text" id="searchText">
<ejs-button id="Search" content="Search" cssClass="e-primary"></ejs-button>
document.getElementById('Search').addEventListener('click', function () {
var val = document.getElementById('searchText').value;
var treegrid = document.getElementById('TreeGrid').ej2_instances[0];
treegrid.search(val);
});
treegrid.search(val): Filters grid by text match across all columns.
Toolbar Export Handler
function toolbarClick(args) {
var tg = document.getElementById("TreeGrid").ej2_instances[0];
var id = args.item.id;
if (id.endsWith('_excelexport')) {
tg.excelExport({ isCollapsedStatePersist });
} else if (id.endsWith('_pdfexport')) {
tg.pdfExport({ isCollapsedStatePersist });
} else if (id.endsWith('_csvexport')) {
tg.csvExport();
}
}
- isCollapsedStatePersist: Boolean to keep tree state (expanded/collapsed).
7. 🧩 Custom Templates & Columns
| Field | Header Text | Template / Special Handling |
|---|---|---|
| AttributeName | Name | — |
| AttrType | Data Type | — |
| IsMultiValue | Is MultiValue | — |
| Values | Values | — |
| TypeList | Document Types | template="#typetemplate" |
| IsAvailable | Is Available | Center-aligned |
| IsDeleted | Is Deleted | Center-aligned |
| AddedBy | Added By | — |
| AddedDate | Added Date | Formatted as M/d/yyyy (in load()) |
| ModifiedBy | Modified By | — |
| ModifiedDate | Modified Date | Formatted as M/d/yyyy |
| Edit | Edit/Update | template="#edittemplate" |
| Delete | Delete | template="#deletetemplate" |
Template Examples
<script id="edittemplate" type="text/x-template">
<a target="_blank" href="/HRImaging/EditAttribute/${Id}">Edit</a>
</script>
<script id="deletetemplate" type="text/x-template">
<a href="/HRImaging/DeleteAttribute/${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>
8. 💬 Modal Dialog & AJAX Loading
A Bootstrap modal is used to dynamically load child details:
<div id="myModal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div id="myModalContent"></div>
</div>
</div>
</div>
var TeamDetailPostBackURL = '/HRImaging/myModalAttribute';
$(".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.");
}
});
});
- Endpoint:
/HRImaging/myModalAttribute?id={Id} - Success: Loads partial view into modal.
9. ⚙️ JavaScript Event Handlers & Utilities
// Format date columns on load
function load() {
var tg = document.getElementById("TreeGrid").ej2_instances[0];
tg.columns.forEach(function(col) {
if (col.field === "AddedDate" || col.field === "ModifiedDate") {
col.format = { type: 'date', format: 'M/d/yyyy' };
}
});
}
// Toggle persistence of collapsed state
var collapsedStatePersist = true;
function onChange(args) {
collapsedStatePersist = args.checked;
}
load(): Date formatting.onChange(): Binds to checkbox (if added) to toggle collapse persistence.- Grid Lines Toggle:
function onChange(e) { var tg = document.getElementById("TreeGrid").ej2_instances[0]; tg.gridLines = e.value; }
10. 🛠️ UML Class Diagram
classDiagram
class DocumentAttributeView {
+int Id
+string AttributeName
+string AttrType
+bool IsMultiValue
+string Values
+List<string> TypeList
+bool IsAvailable
+bool IsDeleted
+string AddedBy
+DateTime AddedDate
+string ModifiedBy
+DateTime ModifiedDate
+List<DocumentAttributeView> Children
}
DocumentAttributeView: Represents each attribute type node.Children: Recursive list for tree structure.
11. 🔧 Usage Example
Controller action to serve this view:
public IActionResult DocumentAttributes()
{
var model = new DocumentAttributeView { /* properties if needed */ };
ViewBag.dataSource = _attributeService.GetAllAttributesWithHierarchy();
return View("DocumentAttributes", model);
}
Load the page at /HRImaging/DocumentAttributes and interact:
- Add New → Opens form to create an index type.
- Search → Enter text, click Search.
- Export → Click toolbar icons (Excel, PDF, CSV, Print).
- View Types → Click “View Types” link in Document Types column to open modal.
- Edit/Delete → Click respective links per row.
12. 🏁 Conclusion
The DocumentAttributes.cshtml view leverages Syncfusion’s TreeGrid to present a powerful, exportable, and searchable interface for managing document attribute types in a hierarchical manner. With intuitive modals, AJAX loading, and full CRUD support, this page provides HRImaging users with a robust tool to define and maintain index types efficiently.
Feel free to extend this template by adding custom filtering menus, advanced styling, or deeper integration with your business logic!
✨ Happy Coding! ✨