How to highlight tree node on click of button in element-ui - element-ui

I am having el-tree> element and 1 button showNode.
so on click of this button i want to highlight a node with given index.
How to call highlight-current on click of button?

From documentation:
highlight-current: whether current node is highlighted
highlight-current is just a read-only attribute, in order to highlight a specific node, you have to call the method setCurrentKey
setCurrentKey: set highlighted node by key, only works when node-key is assigned, the param (key) is the node's key to be highlighted
So, you need first to add a key to every node, using the property key:
node-key: unique identity key name for nodes, its value should be unique across the whole tree
Like following example:
<el-tree
:data="myData"
node-key="id">
</el-tree>
And then, call the method setCurrentKey on the click event attached to your button:
<el-button #click="setCurrentKey(myData[index].id)">Highlight the n-index node</el-button>
I hope it helps you, bye.
Updated: The code above works only on 2.x version, here an example to highlite a node on version 1.4.13 (but I can't expand a node, so I had to expand all the tree):
var Main = {
data() {
return {
data: [{
label: 'Level one 1',
id: 1,
children: [{
label: 'Level two 1-1',
id: 11
}]
}, {
label: 'Level one 2',
id: 2,
children: [{
label: 'Level two 2-1',
id: 21,
children: [{
label: 'Level three 2-1-1',
id: 211
}]
}, {
label: 'Level two 2-2',
id: 22,
children: [{
label: 'Level three 2-2-1',
id: 221
}]
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
};
},
methods: {
handleNodeClick(data) {
console.log(data);
},
renderContent(h, { node, data, store }) {
let btn = h('span', {
props: {type: 'success'},
domProps: {
innerHTML: data.label,
id: "node-id-" + data.id
}
})
return btn
},
handleBtnClick(){
//Highlite the 211
document.getElementById("node-id-211").style.backgroundColor="yellow";
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
#import url("//unpkg.com/element-ui#1.4.13/lib/theme-default/index.css");
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui#1.4.13/lib/index.js"></script>
<div id="app">
<el-tree :data="data" :props="defaultProps" #node-click="handleNodeClick" :render-content="renderContent" :default-expand-all="true"></el-tree>
<el-button #click="handleBtnClick">Highlight the 211 node</el-button>
</div>

Related

How to prevent select2 to call select2:close the second time when selectOnClose is set to true?

I am using Select2 V. 4.0.10
I want to have a select2 that behaves the same way when you select using the Enter key and the Tab key.
What happens is that when selecting using the Tab key, the close event is called twice, which is not what was intended to do.
var data = [
{ id: 0, text: 'New' },
{ id: 1, text: 'In Process' },
{ id: 2, text: 'Draft' },
{ id: 3, text: 'Submitted' },
{ id: 4, text: 'Deleted' }
];
$(".test").select2({
allowClear: true,
selectOnClose: true,
data: data,
placeholder: "Select a status"
});
$("select.test", "body").off("select2:close").on("select2:close", function (e){
// This is called twice
console.log("select2:close");
});
select.test {
width: 200px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js"></script>
<select class="test"></select>
Here are the sequences of the select2 events that are triggered when selecting with the Tab/Enter key.
TAB
select2:opening
select2:open
select2:closing
select2:selecting
change
change.select
select2:closing
select2:close
select2:select
select2:close
ENTER
select2:opening
select2:open
select2:selecting
change
change.select
select2:closing
select2:close
select2:select
As the pattern in always the same, the solution was to create a variable that would be toggled on when select2:select was triggered, and use that to see if it was be used before.
Notice, instead of using the global window object you should rather use a class variable or a prototype property to store this boolean.
var data = [
{ id: 0, text: 'enhancement' },
{ id: 1, text: 'bug' },
{ id: 2, text: 'duplicate' },
{ id: 3, text: 'invalid' },
{ id: 4, text: 'wontfix' }
];
window._select2Select = false;
$(document).on('select2:select', "select", function (e) {
window._select2Select = true;
});
$(".test").select2({
allowClear: true,
selectOnClose: true,
data: data,
placeholder: "Select a status"
});
$("select.test", "body")
.off("select2:close")
.on("select2:close", function(e) {
if(window._select2Select){
window._select2Select = false;
return;
}
console.log("select2:close");
window._select2Select = false;
});

Grid : features groupingsummary doesn't work extjs 6.5.0

enter image description hereI am new with Extjs 6, and i am implementing a Grid with groupping summary features, i tried this two examples :
http://examples.sencha.com/extjs/6.5.0/examples/classic/grid/group-summary-grid.html
but doesn't work, i have this problem in my browzer console.
Have someone an idea about this errors?
enter image description here
GET localhost/Geomap2018/feature/groupingsummary.js?_dc=20170104130840 404 (Not Found)
Uncaught TypeError: c is not a constructor
this is the example which i tried: http://docs.sencha.com/extjs/6.2.0/classic/Ext.grid.feature.GroupingSummary.html
Ext.define('TestResult', {
extend: 'Ext.data.Model',
fields: ['student', 'subject', {
name: 'mark',
type: 'int'
}]
});
var grid = Ext.create('Ext.grid.Panel', {
width: 200,
height: 240,
features: [{
groupHeaderTpl: 'Subject: {name}',
ftype: 'groupingsummary'
}],
store: {
model: 'TestResult',
groupField: 'subject',
data: [{
student: 'Student 1',
subject: 'Math',
mark: 84
}, {
student: 'Student 1',
subject: 'Science',
mark: 72
}, {
student: 'Student 2',
subject: 'Math',
mark: 96
}, {
student: 'Student 2',
subject: 'Science',
mark: 68
}]
},
columns: [{
dataIndex: 'student',
text: 'Name',
summaryType: 'count',
summaryRenderer: function (value) {
return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
}
}, {
dataIndex: 'mark',
text: 'Mark',
summaryType: 'average'
}]
});
var win = Ext.create('Ext.window.Window', {
width: 300,
height: 200,
items: [grid]
});
win.show();
Ext.view.Table.constructFeatures calls Ext.create which in turn calls the following.
feature = Ext.create('feature.' + feature.ftype, feature);
It doesn't look like the feature configuration has any typos, so Ext.create will eventually call the class manager passing the resolved class for the feature.
cls = Manager.get(name);
...
return Manager.getInstantiator(args.length)(cls, args);
From the exception, "c" is "cls" - the feature class. Therefore, I think the class manager is not finding the feature class. Make sure you've added Ext.grid.feature.GroupingSummary to the requires declaration so that the class is loaded and available.

Angular UI Grid not updating directives in cells

I have a ui grid that contains a directive, this directive has an isolated scope and changes it's template basing on some logic.
The problem is that, when sorting (and also when PAGING), the 'logic' of the directive seems to not be correctly "re-evaluated".
In the specific example, the rightmost column should only see some "11" while if you try to sort by id (or the other fields) you'll see some spurios '0' appearing.
this is the ui:
<div ng-app="myapp">
<div ng-controller="myctrl">
<div ui-grid="gridOptions" ng-style="gridStyle"></div>
</div>
</div>
this is the js:
var myapp = angular.module('myapp', ["ngRoute", "ui.grid"])
.controller('myctrl', function($scope) {
$scope.gridOptions = {
data: [{
id: 1,
name: "Max",
other: "pippo",
number: 1
}, {
id: 2,
name: "Adam",
other: "pluto",
number: 0
}, {
id: 3,
name: "Betty",
other: "paperino",
number: 0
}, {
id: 4,
name: "Sara",
other: "fava",
number: 1
}, {
id: 5,
name: "Favonio",
other: "favona",
number: 1
}],
columnDefs: [{
field: "id",
displayName: "ID"
}, {
field: "name",
displayName: "Name"
}, {
field: "other",
displayName: "Other"
}, {
field: "number",
cellTemplate: '<div class="ui-grid-cell-contents"><mydir data="row.entity"></mydir></div>'
}]
};
}).directive("mydir", function() {
return {
restrict: 'E',
scope: {
data: "=",
},
template: '<div><label ng-if="data.number==1">{{set}}</label></div>',
link: function(scope, iElement, iAttrs) {
scope.set = -1;
if (scope.data.number == 0) {
scope.set = 00;
} else {
scope.set = 11;
}
}
}
});
and here's a fiddle:
https://jsfiddle.net/27yrut4n/
Any hint?
In the end it's a known bug:
https://github.com/angular-ui/ui-grid/issues/4869
And I solved using watch like it's said here:
Directive rendered via UI-Grid cellTemplate rendering incorrectly

Fetching all the Project Name for a Project Cumulative Flow Chart in Rally

I am generating a Project Cumulative Flow Chart, which is based on the Project name that I fetch using a "find," however I can't get it working.
Here is the Problem:
1) The "Find" in my code is just fetching one kind of project name, "FE," however, I have a lot of other Project name such as FE, BE, VisualRF, etc. I am not sure what's going on
2) I return this to "storeConfig" inside the chart and then I want try to give "Name" to the "stateFieldName." This is not working! I don't see any graph at all.
Here is the code.
_chart2: function() {
var projectName = this.getContext().getProject()._refObjectName;
console.log("========");
console.log(projectName); <<<<<<<<<< This always prints one name'FE' (My project name are FE, BE, etc)
this.chart = {
xtype: 'rallychart',
storeType: 'Rally.data.lookback.SnapshotStore',
storeConfig: this._getStoreForChart2(),
calculatorType: 'Rally.example.CFDCalculator',
calculatorConfig: {
stateFieldName: this.getContext().getProject()._refObjectName, <<<<< I think usage is not fetching name of all projects
stateFieldValues: ['FE','BE','VisualRF']
},
width: 1000,
height: 600,
chartConfig: this._getChart2Config()
};
this.chartContainer.add(this.chart);
},
_getStoreForChart2: function() {
var obj1 = {
find: {
_TypeHierarchy: { '$in' : [ 'Defect' ] },
Children: null,
_ProjectHierarchy: this.getContext().getProject().ObjectID,
_ValidFrom: {'$gt': Rally.util.DateTime.toIsoString(Rally.util.DateTime.add(new Date(), 'day', -30)) },
State: "Open",
},
fetch: ['Severity','Project','ObjectID','FormattedID'],
hydrate: ['Severity','Project','ObjectID','FormattedID'],
sort: {
_ValidFrom: 1
},
context: this.getContext().getDataContext(),
limit: Infinity,
val: this.Name,
};
return obj1;
},
Though this should not matter but here is the code for the high chart function I am calling above
_getChart2Config: function() {
console.log("starting chart config");
return {
chart: {
zoomType: 'xy'
},
title: {
text: 'Chart2'
},
xAxis: {
tickmarkPlacement: 'on',
tickInterval: 20,
title: {
text: 'Date'
}
},
yAxis: [
{
title: {
text: 'Count'
}
}
],
plotOptions: {
series: {
marker: {
enabled: false
}
},
area: {
stacking: 'normal'
}
}
};
},
Down below you can see 'FE' getting printed:
Thanks a lot!
Kay
stateFieldName is the field which is used to calculate the CFD- usually ScheduleState or a custom dropdown field like KanbanState that captures your process. The stateFieldValues should be the values of that field (Defined, In-Progress, Accepted, Completed, etc.) This doesn't deal with projects at all. Definitely remember to include that field in your hydrate and fetch as well.

jQuery Select2 - Highlighting the child (when the search term matches) instead of its parent in hierarchical list

Select2 3.5.2.
I have some hierarchical data in a select2 list where the parents AND children are all valid selections. If possible, when the search term matches a child, I'd like the child to be highlighted by default instead of the parent.
For example, given the following code...
$("#hdn").select2(
{
width: '300px',
data:
[
{
id: 1,
text: 'Italy',
children:
[
{ id: 2, text: 'Italy - Sardinia' },
{ id: 3, text: 'Italy - Sicily' },
]
},
{
id: 4,
text: 'United Kingdom',
children:
[
{ id: 5, text: 'United Kingdom - Guernsey' },
{ id: 6, text: 'United Kingdom - Jersey' }
]
}
]
});
... if you start typing 'Jer', it currently highlights 'United Kingdom' by default:
Ideally, if you start typing 'Jer', it should highlight 'United Kingdom - Jersey' by default instead.
Because this is a group I still want the parent to show as an option, I just want the child to be highlighted by default instead.
See this fiddle: http://jsfiddle.net/moo_ski_doo/atnph13b/2/
Select2 will highlight the first option which is selectable by default. If you don't want the highlight to sit on "United Kingdom" first, you are going to have to remove the id.
Select2 3.5.2 does not provide an easy way to change how what option is highlighted by default.

Resources