ViewBag.toolbarItems custom
Hi,
I'm trying to call ViewBag.toolbarItems data from controller:
$("#grid").ejGrid({
toolbarSettings: {
showToolbar: true,
toolbarItems: ["add", "edit", "delete", "update", "cancel"],
customToolbarItems: [@Html.Raw(Json.Serialize(ViewBag.toolbarItems))]
},
tried also:
customToolbarItems: [@(new TreeGridCustomToolbarItem() { Text = "Add", TooltipText = "Add" } )]
Not working even I used this method in:
dataSource: ej.DataManager({
json: ej.parseJSON(@Html.Raw(Json.Serialize(ViewBag.datasource))),
adaptor: "remoteSaveAdaptor",
updateUrl: "/Admin/Update",
insertUrl: "/Admin/Insert",
removeUrl: "/Admin/Delete"
}),
to fill row and this one is working fine.
controler:
List tool = new List();
tool.Add(new TreeGridCustomToolbarItem() { Text = "Add", TooltipText = "Add" });
ViewBag.toolbarItems = tool;
Could you please send me how to call viewbag for custom toolbar
Regards,
Kalai Sirajeddine
SIGN IN To post a reply.
5 Replies
VN
Vignesh Natarajan
Syncfusion Team
March 16, 2018 02:03 PM UTC
Hi Kalai,
Thanks for using Syncfusion products.
We have analyzed your query (“I'm trying to call ViewBag.toolbarItems data from controller”) and we have achieved your requirement CustomToolbarItems in the server side. Previously you have used TreeGridCustom toolbaritems. Kindly modify the code as in the below code snippet
Refer the modified code snippet
C#
|
List<CustomToolbarItem> tool = new List<CustomToolbarItem>();
tool.Add(new CustomToolbarItem() { TemplateID = "#Refresh", Text="REF" ,Tooltip="REF" });
tool.Add(new CustomToolbarItem() { TemplateID = "#Collpase", Text = "REF", Tooltip = "REF" });
tool.Add(new CustomToolbarItem() { TemplateID = "#Edit1", Text = "REF", Tooltip = "REF" });
tool.Add(new CustomToolbarItem() { TemplateID = "#Refresh1", Text = "REF", Tooltip = "REF" });
SerializeObject ser = new SerializeObject();
var prop = ser.SerializeToJson(tool);
ViewBag.toolbar = prop; |
CSHTML
|
var data = @Html.Raw(Json.Encode(ViewBag.datasource));
var toolbar = @Html.Raw(Json.Encode(ViewBag.toolbar));
$(function () {
$("#Grid").ejGrid({
dataSource: data,
allowFiltering: true,
allowPaging: true,
toolbarSettings: {
showToolbar: true,
customToolbarItems: ej.parseJSON(toolbar)
}, |
For your convenience we have prepared a sample which can be downloaded from below link
Refer our help documentation for your reference
Regards,
Vignesh Natarajan
KS
Kalai Sirajeddine
March 19, 2018 09:27 AM UTC
Hi Vignesh,
Thanks for help, CustomToolbar is working fine now.(just changed encode in "var toolbar = @Html.Raw(Json.Encode(ViewBag.toolbar));" to Serialize.
Didn't find it in the sended documentation though.
One last query, toolbar items order's before custom one and I wanted to change that so I tried:
toolbarSettings: {
showToolbar: true,
customToolbarItems: ej.parseJSON(toolbar),
toolbarItems: ["delete"]
}
but didn't work.
Regards,
Kalai Sirajeddine
VN
Vignesh Natarajan
Syncfusion Team
March 20, 2018 04:48 PM UTC
Hi Kalai,
Thanks for the update.
Query: “toolbar items order's before custom one and I wanted to change that so I tried:”
We have analyzed your query and we suspect that you need to render the default toolbar items next to custom toolbar items.
It is the default behavior of the Grid to render the default items at first and render the Custom toolbar next to default items.
Can you please explain why you want to change the position of the default toolbar items?
Is there any issue occurring while rendering the default toolbar at first.
Regards,
Vignesh Natarajan
KS
Kalai Sirajeddine
March 21, 2018 08:56 AM UTC
Hi Vignesh,
Since I have delete button on toolbar and add in custom toolbar, I got delete before add wich is not the order it should be.
Think I'm going to change delete to custom toolbar later anyway.
Thanks for help. I will get back to you if needed
Regards,
Kalai Sirajeddine
VN
Vignesh Natarajan
Syncfusion Team
March 22, 2018 07:25 AM UTC
Hi Kalai,
Thanks for the update.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
KS Kalai Sirajeddine
- Mar 15, 2018 02:52 PM UTC
- Mar 22, 2018 07:25 AM UTC