<div class="row">
<div class="col-md-12">
@(Html.EJ().Grid<DVT.Web.Areas.Firms.Models.UserModel>("UsersGrid")
.Datasource((IEnumerable<object>)ViewData["Users"])
.AllowFiltering()
.AllowPaging()
.AllowSorting()
//.EnablePersistence(true) //This appears to break Filtering
.EnableHeaderHover()
.EnableAltRow(true)
.AllowSelection()
.SelectionType(SelectionType.Single)
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.Columns(col =>
{
col.Field("UserID").HeaderText("UserID").IsPrimaryKey(true).Visible(false).Add();
col.Field("FirstName").HeaderText("First Name").TextAlign(TextAlign.Left).Add();
col.Field("LastName").HeaderText("Last Name").TextAlign(TextAlign.Left).Add();
col.Field("Email").HeaderText("Email").TextAlign(TextAlign.Left).Add();
})
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar(true).CustomToolbarItems(
new List<object>()
{
new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Add" },
new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Delete" }
});
})
.ClientSideEvents(eve =>
{
eve.RecordDoubleClick("RecordDoubleClick");
eve.ToolbarClick("ToolbarClick");
})
)
</div>
</div>
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/modalform")
@*<script src="@Url.Content("~/Scripts/Firms_Users_Index.js")"></script>*@
<script id="Add" type="text/x-jsrender">
<a id="addButton" class="e-toolbaricons e-icon">
<img src="../../../Content/icons/SVG/267-plus.svg" alt="Add">
</a>
</script>
<script id="Delete" type="text/x-jsrender">
<a id="deleteButton" class="e-toolbaricons e-icon">
<img src="../../../Content/icons/SVG/272-cross.svg" alt="Delete">
</a>
</script>
<script type="text/javascript">
function RecordDoubleClick(sender) {
var editID = sender.data.UserID; /*Record ID*/
openModal("/Firms/Users/Edit/" + editID); /*Controller Action*/
}
function ToolbarClick(args) {
var gridObj = args.model;
var urlRoot = "/Firms/Users/"; /*Controller Root*/
var url = "";
if (args.itemName == "Add") {
url = urlRoot + "Create";
}
else {
var index = gridObj.selectedRowIndex;
if (index > -1) {
var editID = gridObj.currentViewData[index].UserID; /*Record ID*/
if (args.itemName == "Edit") {
url = urlRoot + "Edit/" + editID;
}
else if (args.itemName == "Delete") {
var canDelete = gridObj.currentViewData[index].CanDelete;
if (canDelete) {
url = urlRoot + "Delete/" + editID;
}
else {
alert("This item cannot be deleted");
}
}
}
}
if (url != "") {
openModal(url);
}
}
</script>
@Html.EJ().ScriptManager()