ion-picker can't get role of button clicked - ionic-framework

I can’t seem to get the button role from ion-picker.
I need to know if it was ‘done’ or ‘cancel’.
Any ideas why this is?
I am just padding this out as stackoverflow is asking me to write some more details as my post is mostly code.
They data is just coming back as follows:
{data: undefined, role: undefined}
let opts: PickerOptions = {
cssClass: 'time-picker',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Done',
role: 'done'
}
],
columns: [
{
name: 'hour',
options: [
{ text: '01', value: '01' },
{ text: '02', value: '02' },
{ text: '03', value: '03' },
{ text: '04', value: '04' },
{ text: '05', value: '05' },
{ text: '06', value: '06' },
{ text: '07', value: '07' },
{ text: '08', value: '08' },
{ text: '09', value: '09' },
{ text: '10', value: '10' },
{ text: '11', value: '11' },
{ text: '12', value: '12' },
{ text: '13', value: '13' },
{ text: '14', value: '14' },
{ text: '15', value: '15' },
{ text: '16', value: '16' },
{ text: '17', value: '17' },
{ text: '18', value: '18' },
{ text: '19', value: '19' },
{ text: '20', value: '20' },
{ text: '21', value: '21' },
{ text: '22', value: '22' },
{ text: '23', value: '23' },
{ text: '24', value: '24' }
]
},
{
name: 'minute',
options: [
{ text: '00', value: '00' },
{ text: '15', value: '15' },
{ text: '30', value: '30' },
{ text: '45', value: '45' }
]
}
]
};
const picker = await this.pickerCtrl.create(opts);
picker.present();
picker.onDidDismiss().then(async data => {
console.log(data);
const hour = await picker.getColumn('hour');
const minute = await picker.getColumn('minute');
this.onChangeFinishTime((hour.options[hour.selectedIndex].value) as number, minute.options[minute.selectedIndex].value as number);
this.isPickerOpen = false;
});

let pickerAction;
const opts: PickerOptions = {
cssClass: 'time-picker',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: value => {
pickerAction = 'cancel';
}
},
{
text: 'Done',
role: 'done',
handler: value => {
pickerAction = 'done';
}
}
],
columns: [
...
const picker = await this.pickerCtrl.create(opts);
picker.present();
picker.onDidDismiss().then(async data => {
if (pickerAction === 'done') {
const hour = await picker.getColumn('hour');
const minute = await picker.getColumn('minute');
this.onChangeFinishTime((hour.options[hour.selectedIndex].value) as number, minute.options[minute.selectedIndex].value as number);
}
this.isPickerOpen = false;
});

You need to move the logic from when the event onDidDismiss() is triggered (which means that the popover has disappeared, regardless of what action made it disappear) to the actual action of clicking the Done button.
This what the handler on Done does here, telling to set the value of the selected entry in the referenced column upon the popover dismissing as a consequence of clicking the Done button.
{data: undefined, role: undefined}
let opts: PickerOptions = {
cssClass: 'time-picker',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Done',
handler: () => {
picker.dismiss().then(async data => {
console.log(data);
const hour = await picker.getColumn('hour');
const minute = await picker.getColumn('minute');
this.onChangeFinishTime((hour.options[hour.selectedIndex].value) as number, minute.options[minute.selectedIndex].value as number);
this.isPickerOpen = false;
});
}
}
],
columns: [
{
name: 'hour',
options: [
{ text: '01', value: '01' },
{ text: '02', value: '02' },
{ text: '03', value: '03' },
{ text: '04', value: '04' },
{ text: '05', value: '05' },
{ text: '06', value: '06' },
{ text: '07', value: '07' },
{ text: '08', value: '08' },
{ text: '09', value: '09' },
{ text: '10', value: '10' },
{ text: '11', value: '11' },
{ text: '12', value: '12' },
{ text: '13', value: '13' },
{ text: '14', value: '14' },
{ text: '15', value: '15' },
{ text: '16', value: '16' },
{ text: '17', value: '17' },
{ text: '18', value: '18' },
{ text: '19', value: '19' },
{ text: '20', value: '20' },
{ text: '21', value: '21' },
{ text: '22', value: '22' },
{ text: '23', value: '23' },
{ text: '24', value: '24' }
]
},
{
name: 'minute',
options: [
{ text: '00', value: '00' },
{ text: '15', value: '15' },
{ text: '30', value: '30' },
{ text: '45', value: '45' }
]
}
]
};
const picker = await this.pickerCtrl.create(opts);
picker.present();

Related

Editable DataTable only works when being the only Widget in the Scaffold body

I have created a custom DataTable, which is editable in a StatefulWidget. The DataTable only loads and works, when there are no other widgets in the Scaffold body property. For example, when I try to add the DataTable in a Column it won't load.
Any help is appreciated, here's the source code of the main.dart, in case that helps.
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Abiturwahlbogen'),
centerTitle: true,
),
body:
Column(
children: const <Widget> [
KursListe(),
],
),
),
),
);
}
class KursListe extends StatefulWidget {
const KursListe({Key? key}) : super(key: key);
#override
State<KursListe> createState() => KursListeState();
}
class KursListeState extends State<KursListe> {
final List<Map> _books = [
{'Kategorie': 'LNG', 'title': 'Deutsch', 'id': 'D', 'LNGFolge': '', 'LNGDauer': '', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
{'Kategorie': 'LNG', 'title': 'Englisch', 'id': 'E', 'LNGFolge': '1', 'LNGDauer': '5', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
{'Kategorie': 'NW', 'title': 'Mathematik', 'id': 'M', 'LNGFolge': '', 'LNGDauer': '', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
{'Kategorie': 'NW', 'title': 'Physik', 'id': 'PH', 'LNGFolge': '', 'LNGDauer': '', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
{'Kategorie': 'GW', 'title': 'Erdkunde', 'id': 'EK', 'LNGFolge': '', 'LNGDauer': '', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
{'Kategorie': 'GW', 'title': 'Geschichte', 'id': 'GE', 'LNGFolge': '', 'LNGDauer': '', 'EF.1': '', 'EF.2': '', 'Q1.1': '', 'Q1.2': '', 'Q2.1': '', 'Q2.2': '', 'ABI': '',},
];
#override
Widget build(BuildContext context) {
return SizedBox(
child: ListView(
children: [_createDataTable()],
));
}
DataTable _createDataTable() {
return DataTable( columnSpacing: 30.0, columns: _createColumns(), rows: _createRows());
}
List<DataColumn> _createColumns() {
return [
const DataColumn(label: Text('Ktg')),
const DataColumn(label: Text('Fach')),
const DataColumn(label: Text('Kürzel')),
const DataColumn(label: Text('Spr-Folge')),
const DataColumn(label: Text('Ab Jg.')),
const DataColumn(label: Text('EF.1')),
const DataColumn(label: Text('EF.2')),
const DataColumn(label: Text('Q1.1')),
const DataColumn(label: Text('Q1.2')),
const DataColumn(label: Text('Q2.1')),
const DataColumn(label: Text('Q2.2')),
const DataColumn(label: Text('Abitur'))
];
}
List<DataRow> _createRows() {
return _books
.map((book) => DataRow(cells: [
DataCell(Text(book['Kategorie'])),
DataCell(Text(book['title'])),
DataCell(Text(book['id'])),
DataCell(Text(book['LNGFolge'])),
DataCell(Text(book['LNGDauer'])),
DataCell(TextButton(onPressed: () {
setState(() {
book['EF.1']= clickConditions(book['EF.1']);
});
},
child: Text(book['EF.1']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['EF.2']= clickConditions(book['EF.2']);
});
},
child: Text(book['EF.2']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['Q1.1']= clickConditions(book['Q1.1']);
});
},
child: Text(book['Q1.1']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['Q1.2']= clickConditions(book['Q1.2']);
});
},
child: Text(book['Q1.2']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['Q2.1']= clickConditions(book['Q2.1']);
});
},
child: Text(book['Q2.1']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['Q2.2']= clickConditions(book['Q2.2']);
});
},
child: Text(book['Q2.2']),
),),
DataCell(TextButton(onPressed: () {
setState(() {
book['ABI']= clickConditions(book['ABI']);
});
},
child: Text(book['ABI']),
),),
]))
.toList();
}
clickConditions (String s1) {
if (s1=='') {
s1 = 'M';
}
else if (s1=='M') {
s1 = 'S';
}
else {
s1 = '';
}
return s1;
}
}
I have tried to use different Widgets like Containers, but the problem seems to be that the DataTable is not compatible.

Customized label and Emphasis label overlap

I try to make the pie chart show 'customized label',change label when the mouse triggered. But except blue data everything else will overlap with 'emphasis label'.
'avoidLabelOverlap' not working.
Is there way?
enter image description here
enter image description here
this is a example
var option = {
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Access From',
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: true,
position: 'center',
formatter: function (params) {
var html = 'TEST';
return html;
}
},
emphasis: {
label: {
show: true,
fontSize: '40',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
}
]
};
Finally,I find a method.
Use mouse event to change label in center.
<!DOCTYPE html>
<html lang="Zh-TW">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.2.2/echarts.min.js"></script>
<meta charset="utf-8">
</head>
<body>
<div id="main" style="width:600px;height:600px;">
</div>
<script>
var myChart = echarts.init(document.getElementById('main'));
var option = {
title: {
text: 'Total',
textStyle: {
fontSize: 35,
},
x: 'center',
y: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Testname',
type: 'pie',
radius: ['40%', '60%'],
center: ['50%', '50%'],
avoidLabelOverlap: true,
textAlign: 'center',
label: {
normal: {
show: true,
formatter: function (params) {
return params.name+'\n'+params.percent+'%'
},
textStyle: {
fontSize: 20
},
},
},
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
},
{
name: 'Testname',
type: 'pie',
radius: ['40%', '60%'],
center: ['50%', '50%'],
avoidLabelOverlap: true,
textAlign:'center',
label: {
normal: {
show: true,
position: 'center',
formatter: '{b}\n{c}',
align: 'center',
verticalAlign: 'middle',
textStyle: {
fontSize: 0
},
},
emphasis:{
show: true,
textStyle: {
fontSize: 35,
fontWeight: 'bold'
},
formatter: '{b}\n{c}'
},
},
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
},
]
};
myChart.setOption(option);
myChart.on('mouseover', { seriesName: 'Testname' }, () => {
myChart.setOption({
title: {
show: false
}
})
})
myChart.on('mouseout', { seriesName: 'Testname' }, () => {
myChart.setOption({
title: {
show: true
}
})
})
</script>
</body>
</html>
Thanks for the accepted answer,
My case was series label was showing like you mentioned in question, and my need was to solve the same problem while hovering the mouse through legend.
Here is my addition.
// series name: Access From
labelOptionAlter = {
series: [
{ label: {
show: false,
position: 'center'
},
}
]
};
labelOptionDefault={
series: [
{ label: {
show: true,
position: 'center'
},
}
]
};
//similar to mouseover.
myChart.on('highlight', { seriesName: 'Access From' }, () => {
myChart.setOption(labelOptionAlter)
})
//similar to mouseout
myChart.on('downplay', { seriesName: 'Access From' }, () => {
myChart.setOption(labelOptionDefault)
})
Future scholars can read more here
I think there's no way to solve this problem.

How to populate a Flutter dropdown box

How do I populate a Flutter Dropdown box?. I have the following key value pair data.
I want to show the user the value (name) and on click get the ID value
[
{'Id': '1', 'Name': 'item 1'}
{ 'Id': '2', 'Name': 'item 2' }
{ 'Id': '3', 'Name': 'item 3' }
]
Use the map function against the list to generate what you need.
final myMapList = [
{'Id': '1', 'Name': 'item 1'},
{ 'Id': '2', 'Name': 'item 2' },
{ 'Id': '3', 'Name': 'item 3' },
];
String _newValue = myMapList[0]['Id'];
...
DropdownButton<String>(
value: _newValue,
onChanged: (String newValue) {
setState(() {
_newValue = newValue;
});
},
items: myMapList.map(
(Map item) {
return DropdownMenuItem<String>(
value: item['Id'],
child: Text(
item['Name'],
);
}).toList(),),

Cannot search on a toggle column in a grid

When I add a toggle column to a grid with a search it does not appear to function. I have modified the Grid with Search Demo to include a toggle. But when I try to search on it the drop down just gives me an "Is" option and I cannot enter anything for the search clause.
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['peter#gmail.com', 'jim#gmail.com', 'jdoe#gmail.com']} },
{ field: 'auth', caption: 'Auth', type: 'toggle' }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
]
jsFiddle: https://jsfiddle.net/c9r6pk7m/4/
While toggle is a valid render value, it's not a valid searches type.
See: http://w2ui.com/web/docs/1.5/w2grid.searches
You could use list instead, though I must admit, I had to "cheat" with the false value, by mapping it to {id:"0", text: "No"}.
$(function () {
$('#grid').w2grid({
name: 'grid',
show: {
toolbar: true,
footer: true
},
multiSearch: true,
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['peter#gmail.com', 'jim#gmail.com', 'jdoe#gmail.com']} },
{ field: 'auth', caption: 'Auth', type: 'list', options: { items: [{id:true, text: "Yes"}, {id:"0", text: "No"}]} }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
],
records: [
{ recid: 1, fname: 'Jane', lname: 'Doe', email: 'jdoe#gmail.com', auth: true },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe#gmail.com', auth: true },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: 'peter#gmail.com', auth: true },
{ recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jim#gmail.com', auth: true },
{ recid: 5, fname: 'Kelly', lname: 'Silver', email: 'peter#gmail.com', auth: true },
{ recid: 6, fname: 'Francis', lname: 'Gatos', email: 'jdoe#gmail.com', auth: true },
{ recid: 7, fname: 'Mark', lname: 'Welldo', email: 'jim#gmail.com', auth: false },
{ recid: 8, fname: 'Thomas', lname: 'Bahh', email: 'jdoe#gmail.com', auth: false },
{ recid: 9, fname: 'Sergei', lname: 'Rachmaninov', email: 'jdoe#gmail.com', auth: false },
{ recid: 20, fname: 'Jill', lname: 'Doe', email: 'jdoe#gmail.com', auth: false },
{ recid: 21, fname: 'Frank', lname: 'Motzart', email: 'jdoe#gmail.com', auth: false },
{ recid: 22, fname: 'Peter', lname: 'Franson', email: 'jdoe#gmail.com', auth: false },
{ recid: 23, fname: 'Andrew', lname: 'Ottie', email: 'jdoe#gmail.com', auth: false },
{ recid: 24, fname: 'Manny', lname: 'Silver', email: 'jdoe#gmail.com', auth: false },
{ recid: 25, fname: 'Ben', lname: 'Gatos', email: 'peter#gmail.com', auth: true },
{ recid: 26, fname: 'Doer', lname: 'Welldo', email: 'jdoe#gmail.com', auth: true },
{ recid: 27, fname: 'Shashi', lname: 'Bahh', email: 'jim#gmail.com', auth: true },
{ recid: 28, fname: 'Av', lname: 'Rachmaninov', email: 'jim#gmail.com', auth: true }
]
});
});
https://jsfiddle.net/c9r6pk7m/9/

extjs pass param to form

I have a gridpanel with two column, first column show username, second column is a actioncolumn with edit button, when click edit button, change the user password by show a window with form and input new password.
How to pass the "username" to the form and show.
I'm trying to use Store.
Is there any other way?
my code
gridpanelview.js
actioncolumn:
/*...config*/
{
xtype: 'actioncolumn',
items: [
{
handler:function(view, rowIndex, colIndex, item, e, record, row) {
var pwdwin = Ext.create('myapp.view.SetPwdWin');
var store = Ext.create(myapp.store.mystore)
mysore.setData(record)
pwdwin.show();
},
icon: 'edit.png',
tooltip: 'change passpword'
}]
}
mywindow.js:
/*...config*/
dockedItems: [
{
xtype: 'form',
dock: 'top',
reference: 'form',
height: 200,
id: 'pwd_form',
bodyPadding: 10,
header: false,
title: 'My Form',
layout: {
type: 'vbox',
align: 'center'
},
items: [
{
xtype: 'textfield',
flex: 1,
id: 'user_name',
maxHeight: 20,
padding: 10,
fieldLabel: 'Name',
editable: false
},
{
xtype: 'textfield',
id: 'new_pwd',
padding: 10,
fieldLabel: 'Password',
inputId: 'new_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
},
{
xtype: 'textfield',
id: 'confirm_pwd',
fieldLabel: 'confirm',
inputId: 'confirm_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
},
{
xtype: 'button',
text: 'OK',
listeners: {
click: 'set_new_pwd'
}
}
]
}
],
set_form_username: function() {
//get Store data
form = this.getReferences().form.getForm();
//how to set username to the label
}
set_new_pwd: function(button, e, eOpts) {
//send username and new username to server
}
Try using getDockingRefItems('pwd_form') or getDockedItems()
For example:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.Button', {
text: 'Click me',
renderTo: Ext.getBody(),
handler: function() {
// way 1
w.getDockedItems()[0].items.items[0].setValue('your user name');
// way2
w.getDockingRefItems('pwd_form')[1].setValue('your user name');
w.show();
}
});
var w = Ext.create('Ext.window.Window', {
title: 'Hello',
height: 200,
width: 400,
dockedItems: [{
xtype: 'form',
dock: 'top',
reference: 'form',
height: 200,
id: 'pwd_form',
bodyPadding: 10,
header: false,
title: 'My Form',
layout: {
type: 'vbox',
align: 'center'
},
items: [{
xtype: 'textfield',
flex: 1,
id: 'user_name',
maxHeight: 20,
padding: 10,
fieldLabel: 'Name',
editable: false
}, {
xtype: 'textfield',
id: 'new_pwd',
padding: 10,
fieldLabel: 'Password',
inputId: 'new_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
}, {
xtype: 'textfield',
id: 'confirm_pwd',
fieldLabel: 'confirm',
inputId: 'confirm_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
}, {
xtype: 'button',
text: 'OK',
listeners: {
click: 'set_new_pwd'
}
}]
}]
});
}
});