I am new to clarity design. I am trying to implement checkbox treeview. But I am not able to read the values which user selects in treeview i.e, not able to achieve 2-way binding. I am trying to do it using ngModel and ngValue. Can you please help?
It seems like you are trying to implement <clr-tree-node [(clrSelected)]="selected"> feature.
If you implement it like shown in the docs with something like the permissions: data for the docs for Selected Tree your HTML will look like this:
<clr-tree-node
*ngFor="let permission of permissions"
[(clrSelected)]="permission.selected">
{{permission.type}}
<ng-template [(clrIfExpanded)]="permission.expanded">
<clr-tree-node *ngFor="let right of permission.rights" [(clrSelected)]="right.enable">
{{right.name}}
</clr-tree-node>
</ng-template>
</clr-tree-node>
You can add/use de-sugared syntax for the clrSelected #Output like this to check which tree-node was selected
<clr-tree-node [clrSelected]="selected" (clrSelectedChange)="checkForChanges()">
And reduce your permissions down to only the selected nodes in checkForChanges().
Update
For the permissions array it is easy to filter out the non-selected nodes with this line:
permissions.filter(item => item.selected);
So, for example lets assume you have a selected property in your component selected: Array<any> = [];
Then, your check for changes might look like this
checkForChanges() {
this.selected.length = 0; // clear the selected array
this.selected = permissions.filter(item => item.selected); // Reduce the array to only selected items.
}
Related
I have created a multi selection select control using Bootstrap select.
By default I need to show dynamically selected items. When I make selected in option ALL selection (<option value="All" selected >All</option>) by default it shows selected in UI. But when do for one option selected its not shows the tick.
Demo is here: https://jsfiddle.net/sharmilashree/L7wzv5k0/10/
(i.e)
<option value="All" selected >All</option>
<option value="EC" selected>EC (Early Childhood)</option>
I suspect the issue is as you commented, here:
$('#myselect').selectpicker().change(function () { toggleSelectAll($(this)); }).trigger('change');
If you drop the trigger('change') it works as expected:
https://jsfiddle.net/Twisty/3pfq5u41/
I guess my question is why trigger a change event? Really, I would think that you only want to execute toggleSelectAll() when the "All" value is selected.
Perhaps something like: https://jsfiddle.net/Twisty/3pfq5u41/2/
Hope that helps.
Wrong event selection:
Replace
$('#myselect').selectpicker().change(function () { toggleSelectAll($(this)); }).trigger('change');
to
$('#myselect').selectpicker().change(function () { toggleSelectAll($(this)); }).trigger('select');
Check for "undefined" as well.
if (control.data('allOptionIsSelected') != allOptionIsSelected && typeof(control.data('allOptionIsSelected')) != "undefined")
{
And you are done!
Happy Coding.
Does anyone have more details on how to use Dynamic Fields in aslagle/reactive-table (I find the documentation confusing.
I'm trying to add a column with a check box, such that as a person clicks on a row, the check box is toggled.
This way a user can page through a table of records and select items, then when they are done selecting I'll save their final choices.
Right now I can only capture click events by row. But I cannot figure out how to save clicks from as a person moves from one page to another.
Here's how I create the checkbox, using a columncell template; I'm using a unique record id (i.e. 'rin') as a html element id.
<template name="checkboxCellData">
<input type="checkbox" id="{{ rin }}" checked="{{ clicked }}">
</template>
Heres the event toggle.
Template.regsUnderReview.events({
'click #reactive-table-1 tbody tr': function (event) {
// When the row is clicked get that rows data
var row = this;
let cb = document.getElementById(row.rin);
if (row.clicked) {
row.clicked=false;
//set check box when row is clikked
cb.checked = false;
} else {
row.clicked = true;
cb.checked=true;
}
}
});
I think I'm only saving the checkbook state in the DOM, and not the correct Reactive table location....I don't want to store the value in the database, because I'll have tons of users saving their selections...I'll only want cache their selections in the web browser and then on final seletion, save the IDs selected to a user settings database.
Meteor sessions may be what you're looking for.
You can initiate one with Session.set("yourKey", "yourValue"), and you can get the data by using Session.get("yourKey"). Sessions in Meteor are also reactive.
If you are using Meteor 1.3+, you will probably have to add the session package with meteor add session in order to use the above methods.
When you create a MDL table, one of the options is to apply the class 'mdl-data-table--selectable'. When MDL renders the table an extra column is inserted to the left of your specified columns which contains checkboxes which allow you to select specific rows for actions. For my application, I need to be able to process some JavaScript when a person checks or unchecks a box. So far I have been unable to do this.
The problem is that you don't directly specify the checkbox controls, they are inserted when MDL upgrades the entire table. With other MDL components, for instance a button, I can put an onclick event on the button itself as I'm specifying it with an HTML button tag.
Attempts to put the onclick on the various container objects and spans created to render the checkboxes has been unsuccessful. The events I attach don't seem to fire. The closest I've come is attaching events to the TR and then iterating through the checkboxes to assess their state.
Here's the markup generated by MDL for a single checkbox cell:
<td>
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select mdl-js-ripple-effect--ignore-events is-upgraded" data-upgraded=",MaterialCheckbox">
<input type="checkbox" class="mdl-checkbox__input">
<span class="mdl-checkbox__focus-helper"></span>
<span class="mdl-checkbox__box-outline">
<span class="mdl-checkbox__tick-outline"></span>
</span>
<span class="mdl-checkbox__ripple-container mdl-js-ripple-effect mdl-ripple--center">
<span class="mdl-ripple"></span>
</span>
</label>
</td>
None of this markup was specified by me, thus I can't simply add an onclick attribute to a tag.
If there an event chain I can hook into? I want to do it the way the coders intended.
It's not the nicest piece of code, but then again, MDL is not the nicest library out there. Actually, it's pretty ugly.
That aside, about my code now: the code will bind on a click event on document root that originated from an element with class mdl-checkbox.
The first problem: the event triggers twice. For that I used a piece of code from Underscore.js / David Walsh that will debounce the function call on click (if the function executes more than once in a 250ms interval, it will only be called once).
The second problem: the click events happens before the MDL updates the is-checked class of the select box, but we can asume the click changed the state of the checkbox since last time, so negating the hasClass on click is a pretty safe bet in determining the checked state in most cases.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
$(document).on("click", ".mdl-checkbox", debounce(function (e) {
var isChecked = !$(this).hasClass("is-checked");
console.log(isChecked);
}, 250, true));
Hope it helps ;)
We currently don't have a way directly to figure this out. We are looking into adding events with V1.1 which can be subscribed to at Issue 1210. Remember, just subscribe to the issue using the button on the right hand column. We don't need a bunch of +1's and other unproductive comments flying around.
One way to hack it is to bind an event to the table itself listening to any "change" events. Then you can go up the chain from the event's target to get the table row and then grab the data you need from there.
You could delegate the change event from the containing form.
For example
var form = document.querySelector('form');
form.addEventListener('change', function(e) {
if (!e.target.tagName === 'input' ||
e.target.getAttribute('type') !== 'checkbox') {
return;
}
console.log("checked?" + e.target.checked);
});
I'm just beginning to experiment in Angular, and confused about how best to approach binding using ng-repeat. I basically get the point about ng-repeat creating a child scope. My problem is much more basic :) For html like this:
<div ng-controller="swatchCtrl" class="swatch-panel">
Swatches
<ul>
<li ng-repeat="swatch in swatchArray" class="swatch">
<input
type="radio"
name="swatches"
ng-model="$parent.currentSwatch"
value="{{swatch}}"
>
<label class="swatch-label">
<div class="swatch-color" style="background-color: #{{swatch.hexvalue}};"></div
><span class="swatch-name">{{swatch.colorName}}</span>
</label>
</li>
</ul>
currentSwatch is:
<pre>{{currentSwatch | json}}</pre>
currentSwatchObj is:
<pre>{{currentSwatchObj | json}}</pre>
how do I tell this to fire??
swatchArray is:
<pre>{{swatchArray | json}}</pre>
</div>
and javascript like this:
function swatchCtrl($scope) {
$scope.swatchArray = [
{colorName:'Red', hexvalue: 'ff0000', selected: 'false'},
{colorName:'Green', hexvalue: '00ff00', selected: 'false'},
{colorName:'Blue', hexvalue: '0000ff', selected: 'false'}
];
$scope.currentSwatch = {};
}
http://jsfiddle.net/8VWnm/
I want to:
a) When the user clicks on a radio button, I want it to set both the colorName and the hexvalue properties of the currentSwatch object. Right now the binding seems to be giving me a stringified object from the array. How do watch the return of currentSwatch so I can parse it back to an available object? Simple, I know, but what am I missing?
b) When the user clicks on a radio button, I think I want that to set the value of the corresponding "selected" key in the original array to "true". Vice versa for unchecking. Let's say that only one swatch can ever be selected at a time in the palette. (I would like in theory to be able to iterate through the array later on, on the supposition that the different keys and values are likely to sometimes not be unique.)
This kinda stuff is super easy with jquery methods, but I'd like to learn the idiomatic angular way. Thanks in advance for any help.
http://jsfiddle.net/8VWnm/54/
Instead of listening to the ng-click event I would set the index of the selected element to a variable called "currentSwatchIndex"
<li ng-repeat="swatch in swatchArray" class="swatch">
<input
type="radio"
ng-model="$parent.currentSwatchIndex"
value="{{$index}}"
>
</li>
The you can $watch value changes of the currentSwatchIndex in your controller and set the selected swatch-Object and selection states in this $watch function:
$scope.$watch('currentSwatchIndex', function(newValue, oldValue) {
$scope.currentSwatchObj = $scope.swatchArray[newValue];
$scope.swatchArray[newValue].selected = true;
$scope.swatchArray[oldValue].selected = false;
});
Only knowing the currentSwatchIndex should be enough to identify the selected swatchObject. So probably you can get rid of the currentSwatchObj and the selected property of your swatchArray.
You can always get the selected swatch programmatically through a array access.
For future users that can come here to do the same in a select, you don't need use any index, the select must be done like this:
http://docs.angularjs.org/api/ng.directive:select
I've got a ListView which contains edit,delete and add. All good here, however the List is too large and I would like give users a serach functionality with text box and button.
When user clicks on search button, List view gets filtered by search criteria.
could someone help me to achieve this please.
Thank you
(In response to the comments on the question...)
Depends a lot on your DOM structure. You'll need to know how the ListView has laid out its elements. For example, if they're all div elements then you'll need to know that for your JavaScript code. (I'm going to assume the use of jQuery, because it's a safe assumption these days.)
Essentially, your filter is going to have at least a text input element:
<input type="text" id="searchFilter" />
You can also have a button to engage the filter, but for brevity let's just filter as the user types:
$(document).ready(function() {
$('#searchFilter').keyup(function() {
// Here you would do your filtering.
});
});
For the filtering itself, you could use the :contains() selector. See information about it here. Basically, you'd hide all of the elements and then show the ones which match. Something like this (untested):
$('#parentDiv div').hide();
$('#parentDiv div:contains(' + $('#searchFilter').val() + ')').show();
The idea is to hide all of the child divs (your selectors may need to be more specific, depending on your DOM) and then show the ones which match the filter. Don't forget, of course, to have a default case to show all if the filter text is empty.
Well, you have to know your underlying structure; say you are rendering a table, you need to write JavaScript to loop through each row and do something like:
$("#table").find("tbody > tr").each(function() {
var row = this;
//loop through the cells, do the string match
var tds = $(this).find("td");
//match the inner HTML of the td to the search criteria, depending on how
//your search critiera is setup
//if not found
$(this).css("display", "none"); //hide the row
});
It depends on how you render your ListView but if you render a table and want to do the filtering client side you could use a jQuery plugin such as UI Table Filter
ended up using this:
protected void btnSearch_Click(object sender, EventArgs e)
{
DS.SelectCommand =
"SELECT ReportName, ReportType,
FROM Table
WHERE ReportName LIKE #param
ORDER BY ReportType Desc";
DS.SelectParameters.Add("Param", searchTxtBox.Text.Replace("'", "''"));
DS.DataBind();
ListView1.DataBind();
}