Good am.
I can't seem to have your code working when I implement it with my codes?
I am actually not using a repository for my grid. When i implement the code, there are no errors, however, the grid is not being shown. However, if i remove the column template and return to my original codes for the grid, it is generating and displaying the grid correctly.
Could you please check the below codes:
controller:
....
private readonly fsdbEntities _db = new fsdbEntities();
//
// GET: /Contracts/
private static bool? _searchServiceIdNo = true;
public ActionResult Index(bool? serviceIdno)
{
_searchServiceIdNo = serviceIdno ?? true;
ViewData["Searching_ServiceIDNo"] = _searchServiceIdNo;
var data = new fsdbEntities().tbl_contract.OrderBy(c => c.service_idno).ToList();
return View(data);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args)
{
IEnumerable data = new fsdbEntities().tbl_contract.OrderBy(c => c.service_idno).ToList();
_db.Configuration.LazyLoadingEnabled = false;
_db.Configuration.ProxyCreationEnabled = false;
return data.GridJSONActions<tbl_contract>();
}
the grid....
....
@model IEnumerable<tbl_contract>
@(Html.Syncfusion().Grid<tbl_contract>("EntityGrid")
.ActionMode(ActionMode.JSON)
.Datasource(Model)
.Caption("Service Details")
.AutoFormat(Skins.Marble)
.AllowSearching(true)
.Scrolling(scroll =>
{
//scroll.AllowScrolling((bool)ViewData["AllowScrolling"]);
scroll.AllowScrolling(true);
//scroll.Width((int)ViewData["Width"]);
})
.Column(column =>
{
column.Add(p => p.service_idno).Visible(false).AllowSearching((bool)ViewData["Searching_ServiceIDNo"]);
column.Add(p => p.service_date).HeaderText("DATE").TextAlign(TextAlignment.Right).Format("{0:dd.MMM.yyyy}").Width(50);
column.Add(p => p.branch_code).HeaderText("CODE").TextAlign(TextAlignment.Right).Width(40);
column.Add(p => p.service_crcno).HeaderText("CRC NO.").TextAlign(TextAlignment.Right).Width(50); column.Add("tbl_contract").HeaderText("DECEASED").TemplateColumn(true).TemplateName("JsonCompleteNameTemplate").TextAlign(TextAlignment.Right).Width(130);
//column.Add(p => p.service_dec_lname).HeaderText("LAST NAME").Width(65);
//column.Add(p => p.service_dec_fname).HeaderText("FIRST NAME").Width(65);
//column.Add(p => p.service_dec_mname).HeaderText("MIDDLE NAME").Width(70);
column.Add(p => p.service_dec_bday).HeaderText("B-DAY").TextAlign(TextAlignment.Right).Format("{0:dd.MMM.yyyy}").Width(50);
column.Add(p => p.service_type).HeaderText("SERVICE").TextAlign(TextAlignment.Right).Width(70);
column.Add(p => p.service_interment).HeaderText("INTERMENT").TextAlign(TextAlignment.Right).Format("{0:dd.MMM.yyyy}").Width(60);
//column.Add(p => p.service_brgy).HeaderText("BARANGAY").TextAlign(TextAlignment.Right).Width(100);
})
.EnablePaging()
.EnableSorting()
.EnableFiltering()
.Mappers(mapper => mapper.InsertAction("AddService")
.SaveAction("SaveService")
.DeleteAction("DeleteService"))
.Editing(edit =>
{
edit.PrimaryKey(key => key.Add(p => p.service_idno));
edit.AllowEdit(true);
edit.AddNewRowPosition(RowPosition.Top);
edit.AllowNew(true);
edit.AllowDelete(true);
})
.ClientSideEvents(events => { events.OnLoad("load").OnActionBegin("Begin").OnActionSuccess("Success"); })
.ToolBar(tool => tool.Add(GridToolBarItems.Search)
.Add(GridToolBarItems.AddNew)
.Add(GridToolBarItems.Edit)
.Add(GridToolBarItems.Delete)
.Add(GridToolBarItems.Update)
.Add(GridToolBarItems.Cancel))
)
as you can see in above code i want to combine three (3) columns, the service_dec_lname, service_dec_fname & service_dec_mname respectively. I would like to do a SUBSTRING command if possible for the service_dec_mname if it has value. I want only to get the 1st letter of the service_dec_mname and have a result of the column template something like Doe, John M.
here is the code for my JsonCompleteNameTemplate.cshtml
@*@using fsdbMvcApps.Models;*@
@model IEnumerable<fsdbMvcApps.Models.tbl_contract>
@*${service_dec_lname}, ${service_dec_fname} SUBSTRING(${service_dec_mname},1,1)*@
@*${service_dec_lname} ${service_dec_fname}*@
${service_dec_lname}
as you can see i have tried some codes as well and still i cant seem to use the column template successfully. Am I missing something here? Do I really need to have a repository in my model to implement the column template?
Thanks again in advance for the help Syncfusion Gurus.
regards,
almond