BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hi Muyiwa,
Thanks for using Syncfusion products.
Query: “I want to develop an editable grid powered by AngularJS and MVC/Web API conected to a SQL Server backend. I was not able to locate the relevant documentation for this,”
Essential Javascript have in-built support to perform editing using WebAPI controller. This can be achieved by using the WebApiAdaptor. Please refer the below code snippet for grid initialization and assigning the WebApiAdaptor adaptor for ej.DataManager.
<div class="row">
<div ej-grid id="Grid" e-datasource="data" e-allowpaging="true" e-editsettings-allowadding="true" e-editsettings-allowdeleting="true" e-editsettings-allowediting="true" e-editsettings-showconfirmdialog="false" e-toolbarsettings-showtoolbar="true" e-toolbarsettings-toolbaritems="tools"> <div e-columns> <div e-column e-field="EmployeeID" e-headertext="Employee ID" e-isprimarykey="true"></div> <div e-column e-field="Name" e-headertext="Employee Name"></div> </div> </div>
</div>
<script> angular.module("GridCtrl", ["ejangular"]) .controller("bodyCtrl", function ($scope) {
//Provide the datasource to the grid. Here the WebApiAdaptor is used. $scope.data = ej.DataManager({ url: "api/Orders", adaptor: "WebApiAdaptor" });
$scope.tools = ["add", "edit", "delete", "update", "cancel"];
}); </script> |
While editing, the data will be posted to the WebAPI controller and processed at the server side. For you convenience, we have created a simple sample with Angular Grid in MVC and the same can be downloaded from the below location.
Sample Location: http://www.syncfusion.com/downloads/support/directtrac/118071/WebAPI-AngularEdit1459652055.zip
In the above sample, we have performed the editing operation using Linq to Sql and please refer the above sample for server side codes.
And also please refer the below link initializing control using AngularJS.
http://help.syncfusion.com/ug/js/default.htm#!documents/angularjs.htm
The properties to the grid control will be provided as the directive value in which the directive will starts with the “e-” followed by property name (in Lowercase). The complex properties will be separated by hypen symbol as e-editsettings-allowadding. Please refer the below link for the available properties in grid.
http://help.syncfusion.com/UG/JS_CR/ejGrid.html
Concepts and features: http://help.syncfusion.com/ug/js/default.htm#!documents/conceptsandfeatures22.htm
Please let us know if you have any queries.
Regards,
Madhu Sudhanan. P
Hi Muyiwa,
Please find the response.
Query #1: “What i am trying to do is to enable filtering etc”
Filtering:
While using remote binding datasource, all the grid actions such as filtering, grouping and sorting should be handled at the server side itself. But in the previously provided sample, we didn’t performed such operations and hence grid actions were not worked.
Now we have modified the Web API controller to handle the grid actions and please refer the below code snippet.
// GET api/<controller> public PageResult<EmployeePhoto> Get(ODataQueryOptions opts) { List<EmployeePhoto> emp = db.EmployeePhotos.ToList();
return new PageResult<EmployeePhoto>(opts.ApplyTo(emp.AsQueryable()) as IEnumerable<EmployeePhoto>, null, emp.Count); } |
The ejDataManager works well OData and the parameter sends to web api will be in OData format. Hence we have used ODataQueryOptions to get parameter from the request. For more information on Odata query support for Web API please refer the below link.
For your convenience, we have modified the previously provided sample and the same can be downloaded from the below location.
Sample Location: http://www.syncfusion.com/downloads/support/directtrac/118071/WebAPI-AngAllOperations-2144667810.zip
Locale:
To localize the grid default string, we have to provide the localization string value by adding a property(property name should be same as locale name) to the object “ej.Grid.locale”. The default property and values of locale “en-US” will be as follows.
ej.Grid.locale["en-US"] = { EmptyRecord: "No records to display", //Editing option localization strings DeleteOperationAlert: "No records selected for delete operation", EditOperationAlert: "No records selected for edit operation", SaveButton: "Save", OkButton: "OK", CancelButton: "Cancel", EditFormTitle: "Details of ", AddFormTitle: "Add New Record", //Key Combination alert message Notactionkeyalert: "This Key-Combination is not avaiable", Keyconfigalerttext: "This Key-Combination has already been assigned to ", //Group drop area and caption format GroupDropArea: "Drag a column header here to group its column", GroupCaptionFormat: "items", //Bulk Editing Alert Messages BatchSaveConifrm: "Are you sure you want to save changes?", BatchSaveLostChanges: "Unsaved changes will be lost. Are you sure you want to continue?", //Pager bar message string PagerInfo: "{0} of {1} pages ({2} items)", //Frozen Alert Messages FrozenColumnsViewAlert: "Frozen columns should be in grid view area", FrozenColumnsScrollAlert: "Enable allowScrolling while using frozen Columns", FrozenNotSupportedException: "Frozen Columns and Rows are not supported for Grouping, Row Template, Detail Template and Batch Editing", //Toolbar tooltip Add: "Add", Edit: "Edit", Delete: "Delete", Update: "Update", Cancel: "Cancel", //Filter menu strings StringMenuOptions: [{ text: "StartsWith", value: "StartsWith" }, { text: "EndsWith", value: "EndsWith" }, { text: "Contains", value: "Contains" }, { text: "Equal", value: "Equal" }, { text: "NotEqual", value: "NotEqual" }], NumberMenuOptions: [{ text: "LessThan", value: "LessThan" }, { text: "GreaterThan", value: "GreaterThan" }, { text: "LessThanOrEqual", value: "LessThanOrEqual" }, { text: "GreaterThanOrEqual", value: "GreaterThanOrEqual" }, { text: "Equal", value: "Equal" }, { text: "NotEqual", value: "NotEqual" }], PredicateAnd: "AND", PredicateOr: "OR", Filter: "Filter", MatchCase: "Match Case", Clear: "Clear"
PrintGrid: "Print", ExcelExport: "Excel Export", WordExport: "Word Export", PdfExport: "PDF Export", ResponsiveFilter: "Filter", ResponsiveSorting: "Sort" };
|
Please refer our online demo of localizing grid.
http://js.syncfusion.com/demos/web/#!/azure/grid/Localization
ShowColumnChooser:
Please refer our below user guide for enabling the column chooser in grid.
http://help.syncfusion.com/ug/js/default.htm#!documents/columns2.htm
Responsive Grid:
To use the adaptive feature in ejGrid we have include the following css files in your view page.
<link rel='nofollow' href="themes/responsive-css/ej.responsive.css" rel="stylesheet" /> <link rel='nofollow' href="themes/responsive-css/ejgrid.responsive.css" type="text/css" rel="stylesheet" /> |
Query #2: Are there any other pages, books or samples that have more detailed information on using angularjs with the grid control?
Please refer our online concept and features section of user guide for more details of using grid features.
http://help.syncfusion.com/ug/js/default.htm#!documents/conceptsandfeatures22.htm
Please let us know if you have any queries.
Regards,
Madhu Sudhanan. P
Hi Muyiwa,
Thanks for the update.
Query 1: “unable to select values in dropdown column”
We have analyzed your code snippets and found that you have given dropdown datasource as object with property names as “id” & “Name” which is the cause of the issue.
We would like to let you know that datasource for the dropdown must be given in value and text format as in the below code snippet.
<div ej-grid id="Grid" e-datasource="data" e-scrollsettings="mysettings" e-allowscrolling="true" e-allowsorting="true"...> <div e-columns> <div e-column e-field="EmployeeID" e-headertext="Employee ID" e-isprimarykey="true" e-textalign="right"></div> <div e-column e-field="Name" e-headertext="Employee Name" e-edittype="dropdownedit" e-datasource="data1"></div> ... </div>
$scope.data1 = [{ text: "One", value: "One" }, { text: "Two", value: "Two" }]; |
Query 2: “relative path was no longer working”
We are able to reproduce the issue and we suggest you to use “@Url.Content()” to set relative path that resolves the issue. Please find the below code snippets.
$scope.data = ej.DataManager({ url: '@Url.Content("~/api/Orders")', adaptor: "WebApiAdaptor" }); |
Alternatively, you can also use the below code snippet to resolve the issue.
$scope.data = ej.DataManager({ url: “../api/Orders", adaptor: "WebApiAdaptor" }); |
For your convenience we have modified the sample and the same can be downloaded from below link.
Please let us know if you need any further assistance.
Regards,
Alan Sangeeth S
Hi Olu,
Thanks for your update.
Please get back to us if you need further assistance. We will happy to assist you.
Regards,
Madhu Sudhanan. P
Hi Muyiwa,
Please find the response.
Query: “How to use ForeignKeyColumn binding in AngularJS and MVC?”
The foreign key column can be defined in grid using the foreignKeyField and foreignKeyValue property. The foreignKeyField property defines the field name of the grid datasource which is used as foreignkey to another datasource and foreignKeyValue is the field in the foreign table.
The foreign key column can be used in the grid as follows.
<div ej-grid id="Grid> <div e-columns> . . . . . . .. . <div e-column e-field="Name" e-type="string" e-foreignkeyfield="text" e-foreignkeyvalue="value" e-datasource="dropdata" e-textalign="right"></div> </div> </div> <script> angular.module("GridCtrl", ["ejangular"]) .controller("bodyCtrl", function ($scope) { . . . . $scope.dropdata = [{ text: "Janet", value: 2 }, { text: "Nancy", value: 9 }, { text: "Balram", value: 4 }, { text: "Maddy", value: 5 }, { text: "Indiana", value: 6 }, { text: "Api", value:7 }] }); </script> |
Now while editing, the dropdownlist will be used while editing the foreign key column. For your kind information, please specify the type property of the column(e-type="string") to do the property casting between the foreignkey values.
For your convenience, we have modified the previously provided sample with the above requirement and the same can be downloaded from the below location.
Sample Location: http://www.syncfusion.com/downloads/support/directtrac/118071/Angular-ForeignKey1473075350.zip
Please let us know if we misunderstood your requirement or if you require further assistance.
Regards,
Madhu Sudhanan. P
Hi Muyiwa,
Thanks for your update.
We will wait to hear from your. Please get back to us if you need further assistance. We will happy to assist you.
Regards,
Madhu Sudhanan. P