How to put a column menu in toolbar of a kendo grid to select the columns as per need?
dataSource: $scope.kDisplayReceivedOrders,
toolbar: ["save", "cancel",
{
template:
'<button class="k-button k-button-icontext " ng-click="confirmReceivedOrder()" >Confirm</button>' +
'<button class="k-button " ng-click="printReceivedOrderDetails()">Print</button>'
}
],
You cannot insert the columnMenu froma a Kendo grid inside a toolbar because Kendo add it to the current grid.
But what you could do is a self implementation of the behavior of this menu inside your own toolbar. I have done it recently for a project.
What I have done:
An angular component.
When clicking on the component I read what columns are visible.
I do that throgh the .getOptions() and then inspecting the columns property of the object returned. The invisible columns will have a hidden=true.
Then in the template I show all the columns with a checkbox to switch the visibility.
hideColumn() and showColumn() should be attached to the action of checking or unchecking a checkbox.
Angular component controller:
init() {
if(this.grid)
this.columns = getColumns(this.grid.getOptions().columns);
}
checkbox(column) {
column.visible === true ? this._objectViewService.grid.showColumn(column.field) : this._objectViewService.grid.hideColumn(column.field);
}
A method to convert from kendo defaults to my visualization system:
function getColumns(columns) {
let cols = [];
columns.forEach(column => cols.push({title: column.title, field: column.field, visible: column.hidden !== undefined ? !column.hidden : true}));
return cols;
}
The template:
<div class="columnDropdownComponent">
<p class="title" ng-mouseover="$ctrl.init()">
<button>Columns<span class="icon-navigation-down"></span></button>
</p>
<div class="dropdown">
<div class="group">
<label ng-repeat="column in $ctrl.columns" ng-class="{'checked': column.visible}">
{{column.title}}
<input type="checkbox" ng-model="column.visible" ng-click="$ctrl.checkbox(column)">
</label>
</div>
</div>
Related
I have used kendo Multiselect dropdown list on my page. When I click on it, it is opening the list from top to bottom(downwards). For my requirement, I need to show it from bottom to top(upwards).
I have checked with kendo UI angular documentation for multiselect component. There are no options are available for this change.
Please help me with this requirement thanks in advance.
<kendo-multiselect kendoMultiSelectSummaryTag [data]="data" (valueChange)="onChange($event)" [filterable]="true"
[(ngModel)]="subValues" [textField]="textField" [valueField]="valueField" [clearButton]="false" [autoClose]="false"
[value]="selectedValue" [popupSettings]="{popupClass: 'popupStyle'}" (keypress)="disableText($event)"
(open)="onOpen($event)" (close)="onClose($event)">
<ng-template kendoMultiSelectItemTemplate let-dataItem>
<input type="checkbox" class="k-checkbox" [disabled]="selectedValue.length===1 && isItemSelected(dataItem.text)"
[checked]="isItemSelected(dataItem.text)">
<label class="k-checkbox-label">{{ dataItem.text }}</label>
</ng-template>
<ng-template kendoMultiSelectGroupTagTemplate let-dataItems>
<span class="k-icon k-i-arrow-s"></span>
{{ dataItems.length }} selected
</ng-template>
</kendo-multiselect>
Screenshot is attached
Example: pop up position
$("#optional").kendoMultiSelect({
autoClose: false,
popup: {
origin: "top left",
position: "bottom left"
},
animation: {
open: {
effects: "slideIn:up"
}
}
}).data("kendoMultiSelect");
Explanation taken from: Telerik forum
...however, you should add some space above the widget. Otherwise, the
screen boundary detection will not allow the desired behavior.
I have a checkbox on a dialog box that is opened when clicking a button in an AngularJS widget in my HTML form:
<form class="m-body" role="form" data-ng-submit="preview($event)" novalidate>
...
<div data-ng-if="widget.name === 'display-box'" ng-dige="hideWidgetHeading()">
<div class="divider"></div>
<div class="row">
...
</div>
...
<div class="row ui-checkbox-row">
<label class="col-sm-4 col-xs-6" data-i18n="Hide widget heading:"></label>
<div class="col-sm-8 col-xs-6">
<label class="ui-checkbox">
<input type="checkbox" name="noWidgetHeading" ng-true-value= true ng-false-value= false ngChange="hideWidgetHeading()" ng-click="hideWidgetHeading()" >
<span></span>
</label>
</div>
</div>
</div>
...
In the ctrl.js file, I have the following function:
angular.module('app.widget').run(function($templateCache){
...
}).controller('WidgetPickerCtrl', function($scope, $timeout, fxTag, gPresets, appWidget){
...
$scope.widget = undefined;
...
$scope.checkboxModel = {
value1 : true,
value2 : false
};
...
var widgetHeadingCheckbox = document.getElementById("noWidgetHeading");
console.log(widgetHeadingCheckbox);
$scope.$watch('widgetHeadingCheckbox', function(){
console.log("Value of checkbox has changed: ", widgetHeadingCheckbox);
});
function hideWidgetHeading(){
if(widgetHeadingCheckbox){
console.log("Value of widgetHeadingCheckbox in 'if': ", widgetHeadingCheckbox);
return widgetHeadingCheckbox;
} else {
console.log("Value of widgetHeadingCheckbox in 'else: ", widgetHeadingCheckbox);
return widgetHeadingCheckbox;
}
}
Currently, when I load the page, and click the button to open the dialog box, the checkbox is displayed on the dialog box unchecked. When I click it, it shows that it is checked, and if I click it again, it becomes unchecked again, as you would expect.
I am trying to use the hideWidgetHeading() JS function above to perform a different action when the dialog box 'Submit' button is pressed, depending on whether the checkbox is selected or not.
At the moment, if I select the checkbox (i.e. it's checked- its value should be true), and click the 'Submit' button on the form, I get the following output in my console:
null
Value of checkbox has changed: null
Value of widgetHeadingCheckbox in else: null
I also get the same output in the console if I click the submit button when the checkbox is not checked...
Why is the value of my checkbox always null... I would expect it to be either true or false, but never null... Do I need to initialise it somewhere? I thought I had already done that in the HTML, when setting its ng-true-value & ng-false-value...
Edit
Following what dcrux has said in their answer, I have changed the HTML for the dialog box on which the checkbox is displayed to:
<div data-ng-if="widget.name === 'umw-tag-box'" ng-hide="hideWidgetHeading">
...
<div class="row ui-checkbox-row">
<label class="col-sm-4 col-xs-6" data-i18n="Hide widget heading:"></label>
<div class="col-sm-8 col-xs-6">
<label class="ui-checkbox">
<input type="checkbox" ... ng-model="hideWidgetHeading">
<span></span>
</label>
</div>
</div>
</div>
When I click the 'settings' button on the widget, the dialog box opens:
However, when I then check the 'Hide widget heading' checkbox, what it actually hides is stuff from the dialog, rather than from the widget:
What I want it to hide is the title bar of the widget itself, not anything from the dialog box:
How can I get it to hide something from the widget, rather than from the dialog box?
use ng-model in your input tag
<input type="checkbox" name="noWidgetHeading" ng-true-value= true ng-false-value= false ngChange="hideWidgetHeading()" ng-model="noWidgetHeading" ng-click="hideWidgetHeading()" />
keep ng-model in your input tag ng-model="noWidgetHeading"
And also instead of reading from document
var widgetHeadingCheckbox = document.getElementById("noWidgetHeading");
console.log(widgetHeadingCheckbox);
Try reading from scope
var widgetHeadingCheckbox = $scope.noWidgetHeading;
console.log(widgetHeadingCheckbox)
It's just suggestion try and let me know
You'll want to change that ngChange to ng-change. Also, the clue is in the method name getElementById() - the id is missing, you have the name, but not the id.
I would fist add ng-model="noWidgetHeading" back to the input.
Then change:
var widgetHeadingCheckbox = document.getElementById("noWidgetHeading");
console.log(widgetHeadingCheckbox);
$scope.$watch('widgetHeadingCheckbox', function(){
console.log("Value of checkbox has changed: ", widgetHeadingCheckbox);
});
to just:
$scope.$watch('noWidgetHeading', function(){
console.log("Value of checkbox has changed: ", $scope.noWidgetHeading);
});
Next:
On you HTML- the input does not require ng-true-value or ng-false-value as using 'true' and 'false' is the default. If you not want to use the default ensure you are using an expression so: ng-true-value="'YES'"
Ensure usage of directives is correct: ngChange should be ng-change.
hideWidgetHeading() is not exposed to the scope so can not be called from the front end. Consider binding it to $scope: $scope.hideWidgetHeading = function(){...}
See if these changes fix the problem.
I'm attempting to insert a md-button-toggle into a button toggle group programatically with Angular but Create Element doesn't seem to work well with non standard HTML tags.
HTML snippet i'm attempting to append:
<md-button-toggle-group class="toggle-box" [vertical]="true" id="button-toggle-group">
<dash-theme (onSelected)="setTheme($event);sidenav.close()"></dash-theme>
<md-button-toggle routerLink="/admin/dashboard" (click)=sidenav.close()>
Admin Dashboard
</md-button-toggle>
</md-button-toggle-group>
Angular attempt:
// adds a View Dashboard button to the side nav bar when
addViewDashboard(): void {
var node = document.createElement('<md-button-toggle routerLink="/' + this.dashboardName
+ '" (click)=sidenav.close() id="view-dashboard-button"> View Dashboard </md-button-toggle>');
document.getElementById("button-toggle-group").appendChild(node);
}
(this.dashboardName is just a string which will be passed into the router)
I realize CreateElement isn't supposed to work like this and can't really think of how else I can manage to do this.
The end product should be something like:
<md-button-toggle-group class="toggle-box" [vertical]="true" id="button-toggle-group">
<dash-theme (onSelected)="setTheme($event);sidenav.close()"></dash-theme>
<md-button-toggle routerLink="/admin/dashboard" (click)=sidenav.close()>
Admin Dashboard
</md-button-toggle>
<md-button-toggle routerLink="/[this.dashboardName Value]" (click)=sidenav.close() id="view-dashboard-button">
View Dashboard
</md-button-toggle>
</md-button-toggle-group>
I would just use an array to represent the button toggle info...
<md-button-toggle-group class="toggle-box" [vertical]="true" id="button-toggle-group">
<dash-theme (onSelected)="setTheme($event);sidenav.close()"></dash-theme>
<md-button-toggle *ngFor="let b of buttons" routerLink="b.route" (click)="b.clickAction()">{{b.title}}</md-button-toggle>
</md-button-toggle-group>
Here's an example of the component property you can use to drive the template.
buttons: any = [
{ title: 'button 1', route: '/admin/dashboard', clickAction: () => { alert('action 1'); } },
{ title: 'button 2', route: '/[this.dashboardName Value]', clickAction: () => { alert('action 2'); } }
]
I am not able to make checkboxes in angular-grid in angularjs and i have used celltemplate but its not binding with my controller
I have tried in my controller:
"cellTemplate":'<input type="checkbox" ng-model="row.isSelected" ng-click=" $scope.gridOptions.selectRow($event,row)">
I am using angular-grid
write input field inside div
cellTemplate: '<div><input type="checkbox" ng-click="grid.appScope.selectRow($event,row)"/></div>'
This is how we have achieved putting a checkbox inside of a ui-grid:
Need to use a template in the column. I have included an ng-click, which needs extra handling
$scope.gridOptions = {
data: $scope.yourData,
columnDefs: [
{
field: "selected",
cellTemplate: "
<div class=\"ui-grid-cell-contents\">
<span ng-cell-text>
<input type=\"checkbox\" ng-model=\"row.entity.selected\"
ng-disabled=\"row.entity.checkBoxDisabled\"
ng-click=\"$event.stopPropagation();grid.appScope.hasChanged()\">
</span>
</div>
"
}
ui-grid appscope
I am new to AngularJS and have some trouble understanding the concept of scope in Angular. I have read some posts on stackoverflow as well as online articles, which advise me to create a custom directive to create an isolate scope, but I am getting nowhere...
As for the project I'm working on, I am trying to make a button that when clicked, will trigger a textarea. However, because of ng-repeat, the textarea is triggered for all buttons while I click only one.
My .js file:
angular.module('myApp')
.controller('myCtrl', function ($scope, Question) {
scope.visible = false;
scope.toggle = function() {
scope.visible = !scope.visible;
};
.directive("myDirective", function () {
return {
scope: {
ngClick: '&',
ngShow: '&'
}
}
});
Here is my HTML file:
<ul>
<li ng-repeat="object in objectList">
<button type="text" myDirective ng-click="toggle()">Click</button>
<textarea myDirective ng-show="visible"></textarea>
</li>
</ul>
Angular is creating child (NOT isolated) scope when ng-repeating, try this out, when you ng-init a variable, it is only visible within that repeat div.
<div ng-repeat="i in [0,1,2,3,4,5,6,7,8,9]" ng-init="visible=false">
<button ng-click="visible=!visible">Toggle</button>
<h1 ng-show="visible">look at me!</h1>
</div>
Plunker
There is no need to use a directive. You need to use object in the foreach to refer each item in the loop.
Add visible to each object in objectList:
$scope.objectList = [
{ visible: false },
{ visible: false },
{ visible: false }
];
Then the toggle button will need to pass the object to toggle:
$scope.toggle = function (object) {
object.visible = !object.visible;
};
The ng-show will need to check object.visible and ng-click will need to pass the object:
<button type="text" ng-click="toggle(object)">Click</button>
<textarea ng-show="object.visible"></textarea>
Plunkr