Can't add new object to KendoUI grid if filter is applied to any column - kendo-grid

I use KendoUI grid with popup edit mode. After applying filter to any column it is not possible to add new object correctly. Pressing Add button many times does not show edit popup. But after clearing the filter empty objects are shown in the grid.
Is there any workaround?

I found a workaround. Instead of standard Add button use toolbar template in which add link "Add" with custom handler triggering grid add. In that handler check if filtering is used on grid and if so store current filtering to a var and remove filtering. Also bind to grid "save" and "cancel" events handlers which will apply previous filtering after adding new object (or cancelling).
<kendo:grid-toolbarTemplate>
<div>
<a class="k-button k-button-icontext" onclick="addItemHandler()">Add</a>
...
var gridFilter;
function addItemHandler() {
var table = $("#myGrid").data("kendoGrid");
gridFilter = table.dataSource.filter();
if (gridFilter) {
table.dataSource.filter(null);
}
table.addRow();
}
function gridSavedHandler(e) {
restoreFilter(e.sender);
}
function gridEditCanceledHandler(e) {
e.preventDefault();
e.sender.cancelChanges();
restoreFilter(e.sender);
}
function restoreFilter(table) {
if (gridFilter) {
table.dataSource.filter(gridFilter);
gridFilter = null;
}
}
$(document).ready(pageInitHandler);
function pageInitHandler() {
var table = $("#myGrid").data("kendoGrid");
table.bind("save", gridSavedHandler);
table.bind("cancel", gridEditCanceledHandler);
}
Workaround is complicated one but really works.

Related

Hey I'm trying to make and edit and mark complete function

I'm trying to get my edit function to work so that when I click on the text, it becomes editable and It stays as what I edit it to. I also want help making a function that adds or removes a class called complete to a list item so that it uses a different CSS style.
here is the git hub https://github.com/EthanKettle/ToDo
const text = document.getElementById('todo-li-${index}').value;
if(text) {
editText(text)
showTodo();
}
save();
};
function markComplete () {
document.getElementById('todo-li-${index}').HTML = `class="complete"`;
}

Add a section widgets dynamically into Card on newSelectionInput OnChangeAction

I'm trying to add a section widgets dynamically to Card/CardService on newSelectionInput OnChangeAction, the card already added.
I did not see any documentation on Google, how to achieve this behavior.
Can someone please direct me to the right documentation or how I can do this.
Thanks
We can add/remove a section from card which is already built in onchange action of input fields.
function getCard(addSection) {
// this is your function to build the card. The initial "getCard" function call does not have any parameter passed, so it will be treated as "false". Hence no section will be added
addSection = addSection || false;
if(addSection) {
// add your section here
}
.....
return card;
}
function OnChangeAction() {
var card = getCard(true);
return CardService.newActionResponseBuilder().setNavigation(CardService.newNavigation().updateCard(card)).build()
}
I hope this solves your problem.

Toggle switch to pass unchecked value

I'm using a checkbox to create a toggle switch as shown in this tutorial
The switch lives in a form where questions can be added dynamically. On submission the form posts as array of each answer back to the page to be processed however as the off switch doesn't pass a value back to the form the answers get out of sync with the answers for the other text fields. Is there any way to set a value for the off switch, i.e. when a check box is left unchecked?
I've tried to use the following to set my off checkboxes to off however it just seems to animate all the switches to on on form submission, anyone any ideas as to what I'm doing wrong?
$('form').submit(function(e){
var b = $("input:checkbox:not(:checked)");
$(b).each(function () {
$(this).val(0); //Set whatever value you need for 'not checked'
$(this).attr("checked", true);
});
return true;
});
You probably want to use Javascript to set a value for each checkbox "switch" in one of two ways:
Option 1: in the html of the switch elements/checkboxes, set the value attribute to zero by default. Then add a javascript click handler for the toggle to check its current value and toggle to the opposite state/value.
Option 2: add Javascript to the form's submit handler (on submit) that checks for any switch elements which have no values and set them to zero before processing form.
Either way should pass a value at all times, and your form should be able to keep track of all input states.
This snippet did the trick, as Anson suggested this finds all the checkboxes and sets them to either on or off on form submission:
$('form').submit(function () {
$(this).find('input[type="checkbox"]').each( function () {
var checkbox = $(this);
if( checkbox.is(':checked')) {
checkbox.attr('value','1');
} else {
checkbox.after().append(checkbox.clone().attr({type:'hidden', value:0}));
checkbox.prop('disabled', true);
}
})
});

How to fire an event whenever `<my-view#>` is active (i.e. comes into view)?

Using Polymer Starter Kit as an example, I would like to have different <app-toolbar> in <my-app> (using property headerType) based on different <my-view#>, i.e.
<my-view1> => headerType = 'my-view1-header'
<my-view2> => headerType = 'my-view2-header'
In my <my-app>, I have created a property headerType and use <dom-if> to show/hide different <app-toolbar>.
My question is how would I always fire an event to <my-app> and set headerType = my-view#-header whenever <my-view#> is active (i.e. comes into view).
I have tried the polymer lifecycle, such as ready(), attached(), etc, and I understand they are only trigger during dom-related events.
I eventually use the _pageChanged observer to call a function on <my-view#>. Below are the snippet of the code.
_pageChanged: function(page) {
let onLoad = function () {
let selected = this.$.ironpages.children[page];
if (Object.getPrototypeOf(selected).hasOwnProperty('viewSelected')) {
selected.viewSelected();
}
}
// Load page import on demand. Show 404 page if fails
var resolvedPageUrl = this.resolveUrl('my-' + page + '.html');
this.importHref(resolvedPageUrl, onLoad, this._showPage404, true);
},
There is some example in Polymer shop template where you can execute something when the visibility of your view change with iron-pages.
you just need to add a property for example visible in each of your view element with Boolean type and observe that property to check whatever the view is visible or not, and then in your iron-pages you need to add selected-attribute property and the value is visible. check Polymer Shop Template.

AngularJs Array not Binding To Template

I have a controller named dataController, two services, named dataHttpServices and dataLocalServices and an html template, some directives.
In my html template, I have two different tabs uses same controller and add item to list in my controller from two different places.
In debug mode, I see the data change properly but the data binding is not working properly.
I don't know What is my mistake, help please. In code;
Here is Html;
<div
class="metadataSelect"
layout="column"
ng-model="selectedItems"
ng-show="selectedItems.length > 0">
<div layout="row" ng-repeat="item in selectedItems">
{{item.Name}}
</div>
</div>
Here is the controller;
$scope.addSelectedItem = function (selectedItem) {
var found = false;
var self = this;
dataLocalService.addSelectedItem(selectedItem);
$scope.selectedItems = dataLocalService.getSelectedItems();
};
And here is the service;
this.selectedItems = [];
this.addSelectedItem = function (item) {
this.selectedItems.push(item);
};
this.getSelectedItems = function () {
return this.selectedItems;
};
I call addSelectedItem from scope in two different button's click event with ng-click.
If I first add an item by click the first button and click the second button (first click the first button), the button binds the array to div correctly.
But when I add an item by click the second button before click the first button, the array does not bind to div.
After add some items to array by click the second button, when I click the first button, bind all the elements to div. For example three element at once but doesn't bind without clicking the first button.
What is my mistakes. Thanks for helps.
I solved it with using $scope.$watch. And I think the problem is their scope is different because i create controller twice with ng-controller. Here is the code snippet i found to solve it.
$scope.$watch('selectedItems', function () {
$scope.selectedItems = $metadataLocalService.getSelectedItems();
});
This solves my problem. Because watch is tracking the related data changes and etc.