How to access kendo grid with the help of angular directive? - angularjs

I have the following structure of my grid
$scope.grid = $("#prospectsGrid").kendoGrid({
columns: [
{ template: "<input type='checkbox' class='checkbox' />", width: "3%" },
{ template: "#= FirstName + ' ' + LastName #", title: "Name" },
{ field: "FirstName", hidden: true },
{
command: [
{
name: "edit",
text: "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>"
}
}).data("kendoGrid");
As you can see I am accessing this grid with the help of an identifier that is #prospectsGrid. Now without changing any of the functionality inside the grid, I need to replace the identifier (#prospectsGrid) with some angular element. How can I do that? Any help would be appreciated.
Just for reference my HTML Code is
<div id="prospectsGrid" class="gridcommon"></div>

As micjamking says in comments, you need inject in your module KendoUI directives.
angular.module("myApp",["kendo.directives"])
Then you will can use in your html code something like this
<div kendo-grid="myKendoGrid"
k-options="myKendoGridOptions">
</div>
In controller:
angular.module("managerOMKendo").controller("myController", function ($scope) {
// Functions controller
$scope.createMyGrid = function () {
$scope.myKendoGridOptions = {
columns: [ {
field: "FirstName",
template: "<input type='checkbox' class='checkbox' />", width: "3%"
},
command: [{
name: "edit",
text: "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>"
}]
// Here you can put your complete configuration. Check official example
}
}
}
// Main thread
$scope.createMyGrid(); // call the function that creates the grid
});
Here is the official example
It´s possible that you need change something. For example where I have written text, maybe you have to write template. It´s hard without plunker.
Good luck!

Related

Umbraco 7 - Custom Macro Parameter Editor - RTE

I hope this will help others too as there isn't a lot of documentation about this exactly.
I want to use a RTE (rich text editor) within a macro I've created to handle page sections.
I have successfully rendered the RTE within the macro. I can select my macroRte from the macro parameters panel. It even renders where I edit the values of my page section. I have attributed the alias of "macroRte" to the parameter.
However, it is not storing the values. Each time I press submit it is wiping the content.
I'm no Angular expert but i think that's the problem. Code below. Thank you.
View
<div ng-controller="CustomSectionEditController" class="umb-editor umb-rte">
<umb-editor model="macroRte">
<div ng-model="model.value">{{model.value}}</div>
</umb-editor>
Controller
angular.module("umbraco").controller("CustomSectionEditController", function ($scope) {
$scope.macroRte = {
label: 'bodyText',
description: 'Load some stuff here',
view: 'rte',
config: {
editor: {
toolbar: ["code", "undo", "redo", "cut", "styleselect", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "table", "umbembeddialog"],
stylesheets: ["rte"],
dimensions: { height: 400 },
valueType:"STRING"
}
}
};
});
Render
#inherits Umbraco.Web.Macros.PartialViewMacroPage
<div class="lh-text">
#Model.MacroParameters["macroRte"];
</div>
Any ideas? :)
using this, https://github.com/engern/Umbraco-custom-macro-parameters/tree/master/App_Plugins/MacroRichText - I was able to solve my problem.
The view needs to be changed to the following
<div ng-controller="CustomSectionEditController">
<ng-form>
<umb-editor model="macroRte"></umb-editor>
</ng-form>
</div>
The controller needed the following code (add under view
value: $scope.model.value,
and an additional scope control
$scope.$watch("macroRte.value", function (newValue, oldValue) {
$scope.model.value = newValue;
});
The controller now looks like this
angular.module("umbraco").controller("CustomSectionEditController", function ($scope) {
$scope.macroRte = {
label: 'bodyText',
description: 'Load some stuff here',
view: 'rte',
value: $scope.model.value,
config: {
editor: {
toolbar: ["code", "undo", "redo", "cut", "styleselect", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "table", "umbembeddialog"],
stylesheets: ["rte"],
dimensions: { height: 400 },
valueType:"STRING"
}
}
},
$scope.$watch("macroRte.value", function (newValue, oldValue) {
$scope.model.value = newValue;
});
});
I hope this help others.

Angular-Formly can i render html within the form? (with scope vars)

I have a row based template and i need to display a calculation result within my form. the value is stored in the view model variable calc.
simple html element approach didnt work,
{
key: 'html',
template: '<div>' +
'Hello the value is {{vm.calc}}' +
'</div>'
}
any tips?
Create a type similar to
formlyConfigProvider.setType({
name: 'calculationResult',
template: "<div>Hello the value is {{to.calc}}</div>",
wrapper: ['bootstrapLabel']
});
then add this as a field to your form
{
key: 'taskList',
type: 'calculationResult',
templateOptions: {
label: 'Calculation Result',
calc: ''
},
controller: function ($scope) {
$scope.to.calc = $scope.model.c * $scope.model.b;
}
}
I don't see any other better way to make the calculation display as a normal field value.

I want to write a custom directive for ui-grid with different input columnDefs

This is my Controller
$scope.usersList = {};
$scope.usersList = {
paginationPageSizes: [10,15, 20],
paginationPageSize: 10,
columnDefs: [
{ name: 'userId', cellTemplate: '<div class="ui-grid-cell-contents"><a ui-sref="appSetting.userSelected({userId: row.entity.userId})">{{ row.entity.userId }}</a></div>' },
{ name: 'firstName' },
{ name: 'lastName' },
{ name: 'emailId' },
{
name: 'action',
cellTemplate: '<div>' +
' <button ng-click="grid.appScope.sampledetails()">Delete</button>' +
'</div>',
enableSorting: false,
enableColumnMenu: false
}
]
};
and this is my .cshtml
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
I want to write this in such a way that it should be used in other .cshmtls, but the columnDefs varies depending on table column name. How should I write in such a way that ths user should give the columnsDefs in directive along with pagination?
Your question is hard to understand, hopefully I got it right. You want to define default-settings for your grid but enable the user to input some special settings if needed?
Warp ui-grid in your own directive. Pass your wanted arguments into that directive and create default settings in your directive.
Your .cshtml. You pass your settings variable into that.
<my-grid options="usersList" />
Your Directive. Grab the settings there (see options: '=') and bind that to controller or scope.
angular.module('app').directive('myGrid', myGrid);
function myGrid() {
return {
templateUrl : 'grid.html',
controller : 'GridCtrl',
controllerAs : 'grid',
restrict: 'E',
scope: {
options : '=',
},
bindToController: true,
};
}
Your Controller. Now you can access your settings in that controller.
There you could combine the default settings with your inserted settings and pass that into the directive template.
angular.module('app').controller('GridCtrl', GridCtrl);
function GridCtrl() {
var grid = this;
console.log(grid.options); // containts your settings
grid.gridOptions = {
paginationPageSize: grid.options.paginationPageSize,
...,
columnDefs: grid.options.columnDefs
etc
}
}
And your grid.html, you pass the combined settings into the grid-API.
<div id="grid1" ui-grid="grid.gridOptions" class="grid"></div>
There are many more details to watch out for, but thats a possible setup.
e: I made a Plunkr for another similar question. For future reference.

Kendo grid editable template from directive

I am trying to create a kendo grid (angularjs) and attached a personalized editor <div my-directive-editor></div> via grid options editable.template. On my directive editor (angularjs directive), i specify the structure of HTML from remote file and link it via templateUrl. Upon running the application, everything works great when i first click the Add New Entry but when i cancel the popup dialog and click again the Add New Entry an error will show $digest already in progress in angular format.
I tried instead using templateUrl I used template and formatting the whole HTML structure as string and passed it there and it goes well without the error but as i can see, it is hard for the next developer to manage the very long HTML string so it would be great if i can separate it to remote file and just link it to templateUrl. I prepared a dojo to play with CLICK HERE the content of TestTemplate.html is the HTML string from template.
This is my directive
app.directive('grdEditor',
[
function () {
return {
restrict: 'A',
replace: true,
scope: {
dataItem: '=ngModel'
},
//template: '<div><table><tr><td>Name</td><td><input ng-model="dataItem.Name" class="k-input k-textbox" /></td></tr><tr><td>Birthdate</td><td><input kendo-date-picker k-ng-model="dataItem.Birthdate" /></td></tr><tr><td>Gender</td><td><input kendo-combo-box k-ng-model="dataItem.Gender" k-options="optGender" /></td></tr></table></div>',
templateUrl: 'http://localhost/Angular/TestTemplate.html',
/*template: function(){
return '<div><table><tr><td>Name</td><td><input ng-model="dataItem.Name" class="k-input k-textbox" /></td></tr><tr><td>Birthdate</td><td><input kendo-date-picker k-ng-model="dataItem.Birthdate" /></td></tr><tr><td>Gender</td><td><input kendo-combo-box k-ng-model="dataItem.Gender" k-options="optGender" /></td></tr></table></div>';
},*/
controller: function ($scope, $attrs, $timeout) {
$scope.optGender = {
dataTextField: 'Text',
dataValueField: 'Value',
dataSource:
{
data: [
{
Text: 'Male',
Value: 1
},
{
Text: 'Female',
Value: 2
}]
}
};
}
};
}
]);
and this is my kendo grid options (partial)
$scope.optGrid = {
editable: {
mode: "popup",
window: {
minHeight: '320px',
minWidth: '365px',
},
template: '<div grd-editor ng-model="dataItem"></div>',
},
toolbar: ['create', 'excel'],
excel: {
allPages: true
},
.....................
Any help would be appreciated.
TIA
i think a there is problem with templateUrl. you don't need to give http://
you just need to give path from your base directory or directory of your index.html

How to do validation in $ionicPopup?

I'm trying to use $ionicPopup to handle login/registration on my app.
I'm opening it from a service, so I created a new scope and attached it to the ionicPopup.
It looks something like this:
$ionicPopup.show
template: '''
<form name="loginForm" novalidate>
...
</form>
''',
scope: $scope,
buttons: [
{
text: 'Cancel',
},
{
text: '<b>Save</b>',
type: 'button-positive',
onTap: ( e ) ->
form = $scope.loginForm #why is it undefined?
}
]
So I named the form as loginForm, and I want to access it inside the onTap function to handle validation. But the loginForm does not exists on the $scope, like it would in a normal form validation inside a controller.
How should I handle the validation here?
If you give ionicpopup a templateUrl, instead of hard coded template string, you can use a regular controller inside the template that does the validation.
I deleted all the ionicpopup related buttons and placed the necessary buttons inside the template.
In this way I was able to control the ionicpopup's state from the controller (i.e. closing the popup).
I found solution, it works for me. All you need to change is define in controller your form:
$scope.form = {
loginForm: {}
};
$ionicPopup.show
template: '''
<form name="form.loginForm" novalidate>
...
</form>
''',
scope: $scope,
buttons: [
{
text: 'Cancel',
},
{
text: '<b>Save</b>',
type: 'button-positive',
onTap: ( e ) ->
form = $scope.form.loginForm
}
]
Using my solution, you don't have to delete the ionic popup buttons.
What you can do to validate, is by using ng-Model.
You don't have to use <form>. So I remove <form>.
$ionicPopup.show
template: '<input name="username" ng-model="data.username">',
scope: $scope,
buttons: [
{
text: 'Cancel',
},
{
text: '<b>Save</b>',
type: 'button-positive',
onTap: ( e )
var user_name = $scope.data.username
// do validation here
if(user_name != 'undefined') {
...
}
}
]
I prefer not to remove the ionic popup buttons. Hope it is useful to others. cheers!
Use
onTap: ( e )
e.eventPreventDefault()
var user_name = $scope.data.username
// do validation here
if(user_name != 'undefined') {
...
}

Resources