how to achieve this with react.js? - html

Hi I want to build toggle box which have three columns in a row like below.
the dummy data looks like below
export const topicDummy: TopicData =
[
{
id: 1,
name: '넷플릭스',
url: 'netflix'
},
{
id: 2,
name: '어도비',
url: 'adobe'
},
{
id: 3,
name: '왓챠',
url: 'watcha'
},
{
id: 4,
name: '방돌이/방순이',
url: 'roommate'
},
{
id: 5,
name: '신문구독',
url: 'newspaper'
},
{
id: 6,
name: '공동구매',
url: 'share'
},
{
id: 7,
name: 'KTX',
url: 'train'
},
{
id: 8,
name: '기타',
url: 'etc'
},
]
To achieve this,
I built function which return jsx elements.
But I don't want to build function every times when I want to build box like this.
how can I do with this?

With a little bit of styleing this will look just like the one in your image. It's written in JavaScript not TypeScript, but i'm pretty sure you know how to change that. (I never used TypeScript).
If you want this not to re-render each time you should probably read the documentation of React.memo().
const ToggleMenuBox = ({ goToLink }) => topicDummy.map(item =>
<div key={item.id} onClick={goToLink(item.url)} style={styles.element}>
{item.name}
</div>
)
export default () => {
const goToLink = url => () => {
console.log("Redirecting to", url)
}
return (
<div style={styles.root}>
<ToggleMenuBox goToLink={goToLink}/>
</div>
)
}
const styles = {
root: {
display: 'flex',
flexDirection: 'row',
width: 'calc(100% - 40px)',
backgroundColor: 'gray',
flexWrap: 'wrap',
borderRadius: 10,
padding: 5,
margin: '0 auto',
},
element: {
width: '33%',
textAlign: 'center',
cursor: 'pointer'
}
}

Related

update data in vue with method and axios

I want to display a graph on my web interface. I want to implement the web interface with vue js. For this I pass data from my backend to my frontend with axios. I can display an empty graph on my rsurface. But the data I pass is not displayed. What is wrong with my code that my data is not displayed on the graph.
In the following you can see my implemented code.
<b-container class="ml-auto">
<b-row>
<b-col>
<vue-plotly :data="dataA" :layout="layout" :options="options"/>
</b-col>
</b-row>
</b-container>
export default {
components: {
VuePlotly,
},
data() {
return {
dataA: [{
x: [],
y: [],
}],
layout: {
title: 'ScreePlot',
bargap: 0.05,
xaxis: {
range: [0, 9],
title: 'x',
tick0: 0,
dtick: 1,
},
yaxis: {
range: [0, 2000],
title: 'y',
tick0: 0,
dtick: 1,
},
},
options: {
displayModeBar: false,
responsive: true,
watchShallow: true,
autoResize: true,
},
};
},
mounted() {
this.getScreePlot();
},
methods: {
getScreePlot() {
const path = 'http://localhost:5000/Diagramm';
axios.get(path)
.then((res) => {
this.dataA.x = res.data.x;
this.dataA.y = res.data.y;
})
.catch((error) => {
// eslint-disable-next-line
console.error(error);
});
},
},
};
In case this definition
dataA: [{
x: [],
y: [],
}],
You should fill like this:
.then((res) => {
this.dataA.push(
{
x: res.data.x,
y: res.data.y
}) ;
})

Editable Data Tree Grid in Angular 7+

What is the quickest and easiest way to implement an editable tree grid in Angular 7 (and above) ? I have tried to use ng angular-tree-grid, but got stuck, at the below code i implemented so far.
Template:
<db-angular-tree-grid #angularGrid [data]="data"
[configs]="configs"
(rowdelete)="onRowDelete($event)"
(rowsave)="onRowSave($event)"
(rowadd)="onRowAdd($event)">
</db-angular-tree-grid>
I have been unable to get the onRowAdd() and onRowDelete() methods to work. I need to call a POST endpoint on my c# webApi, within onRowAdd().
Typescript:
export class GridComponent {
#ViewChild('angularGrid') angularGrid: AngularTreeGridComponent;
data: any = [
{ id: 1, planName: 'Functional Test',parent: 0},
{ id: 2, planName: 'Non Functional Test', parent: 0},
{ id: 3, planName: 'Component', parent: 1}
];
configs: any = {
id_field: 'id',
parent_id_field: 'parent',
parent_display_field: 'planName',
actions: {
add: true,
edit: true,
delete: true,
edit_parent: true,
add_parent: true,
delete_parent: true,
resolve_add: true,
resolve_delete: true,
resolve_edit: true
},
css: { // Optional
expand_class: 'fa fa-caret-right',
collapse_class: 'fa fa-caret-down',
add_class: 'fa fa-plus',
edit_class: 'fa fa-pencil',
delete_class: 'fa fa-trash',
save_class: 'fa fa-save',
cancel_class: 'fa fa-remove',
},
columns: [
{
name: 'planName',
header: 'PlanName',
editable: true
}
]
};
onRowAdd($e) {
const data = $e.data;
setTimeout(() => {
$e.resolve();
}, 1000);
}
onRowSave($e) {
const data = $e.data;
setTimeout(() => {
$e.resolve();
}, 1000);
}
onRowDelete($e) {
setTimeout(() => {
$e.resolve();
}, 1000);
}
}

ExtJS4: How to pass arguments to initComponent

I am using Sencha Architect 2. I am trying to generate a generic UI element with a text search and a table displaying the results. Generic means I want to use it for several different type of searches, e.g. for users, or roles or still something else.
So what I definitely like in this context about Sencha Architect 2 is that it always generates classes. Here is my generated class:
Ext.define('ktecapp.view.ObjSearchPanel', {
extend: 'Ext.container.Container',
alias: 'widget.objsearchpanel',
height: 250,
id: 'UserSearchPanel',
itemId: 'UserSearchPanel',
width: 438,
layout: {
columns: 3,
type: 'table'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'textfield',
itemId: 'txtSearchText',
fieldLabel: 'Search Text',
colspan: 2
},
{
xtype: 'button',
id: 'searchObj',
itemId: 'searchObj',
text: 'Search',
colspan: 1
},
{
xtype: 'gridpanel',
height: 209,
itemId: 'resultGrid',
width: 430,
store: 'UserDisplayStore',
colspan: 3,
columns: [
{
xtype: 'gridcolumn',
width: 60,
dataIndex: 'ID',
text: 'ID'
},
{
xtype: 'gridcolumn',
width: 186,
dataIndex: 'DISPLAYNAME',
text: 'Displayname'
},
{
xtype: 'gridcolumn',
width: 123,
dataIndex: 'JOBTITLE',
text: 'Job Title'
},
{
xtype: 'actioncolumn',
width: 35,
icon: 'icons/zoom.png',
items: [
{
icon: 'icons/zoom.png',
tooltip: 'Tooltip'
}
]
}
],
viewConfig: {
},
selModel: Ext.create('Ext.selection.CheckboxModel', {
})
}
]
});
me.callParent(arguments);
}
});
The problem I am having is that everything needs to be pretty customizable, dataIndexes of the columns, the store, ...
So how can I get a constructor like function for the class ObjSearchPanel where I pass all that information? In the code above all this looks pretty much hardcoded...
Thanks in advance
Kai
use config,
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Class-cfg-config
Ext.define('SmartPhone', {
config: {
hasTouchScreen: false,
operatingSystem: 'Other',
price: 500
},
constructor: function(cfg) {
this.initConfig(cfg);
}
});
var iPhone = new SmartPhone({
hasTouchScreen: true,
operatingSystem: 'iOS'
});
iPhone.getPrice(); // 500;
iPhone.getOperatingSystem(); // 'iOS'
iPhone.getHasTouchScreen(); // true;
iPhone.hasTouchScreen(); // true
Actually (in ExtJS 4), when you pass a config object to the constructor, this config object is assigned to this.initialConfig variable and still available to other functions of the class. So you can use it in the initComponent.
You still can find code in ExtJS 3.3 like this Ext.apply(this, Ext.apply(this.initialConfig, config)); in the initComponent of classes. However, use it at your own risk because this is not in the document of ExtJS 4, only found it in the source code.

Sencha - How to display images in xtype panel html where image source is load from model

Below is code from Store where i have hardcoded data for testing.
`Ext.regStore('CalendarStore', {
model: 'CalendarModel',
sorters: [{
property: 'id',
direction: 'ASC'
}],
proxy: {
type: 'localstorage',
id: 'calendar-app-store'
},
data: [
{ id: 1, title: 'January', image: 'jan.iPNG'}
, { id: 2, title: 'Febuary'}
, { id: 3, title: 'March'}
, { id: 4, title: 'April'}
, { id: 5, title: 'May'}
, { id: 6, title: 'June'}
, { id: 7, title: 'July'}
, { id: 8, title: 'August'}
, { id: 9, title: 'September'}
, { id: 10, title: 'October'}
, { id: 11, title: 'November'}
, { id: 12, title: 'December'}
]
});`
and i am trying to load image i.e 'jan.PNG' which i have in store and source changes with month.i am able to display month name from {title} but not from {image}.All i get is a ?mark on the app.
I read that if i get ? mark then the src path is incorrect but if i give
'html : '<img style="height: 700px; width: 500px;" src="jan.iPNG "/>' '
or
src="http://www.mypics/jan.iPNG "/>' '
these display fine.
below is the view
'CalendarApp.views.viewCalendar = new Ext.form.FormPanel({
id: 'viewCalendar',
scroll: 'true',
items:[{
xtype: 'textfield',
name: 'title'
// label: 'title'
},
{
xtype: 'panel',
name :'image',
html : '<img style="height: 700px; width:500px;" src="'+'image'+'">'
}],
dockedItems:[CalendarApp.views.calTopToolbar]
});'
Also tried variation src="image"> but the image doesnt display. Help tearing my hair off
First save the image in custom folder where your files are present.
and use below code,
{
xtype: 'panel',
icon: 'jan.png', // specify the path of the image
width:100, // if u want to specify the width for image
height:80, // if u want to specify the height for image
iconMask: false,
handler: jan // if u want to handle the click event
}
another option is u can define the image in html file by
<style>
.NewIcon {
-webkit-mask-box-image: url('../img/new_icon.png');
}
</style>
and specify this New icon in the js file where you want to use it
{
xtype: 'panel',
iconCls: 'NewIcon ',
width:100,
height:80,
iconMask: false,
handler: newicon
}

Sencha - Display images in xtype panel html where image source is load from model

Below is code for Store where i have hardcoded data for testing.
`Ext.regStore('CalendarStore', {
model: 'CalendarModel',
sorters: [{
property: 'id',
direction: 'ASC'
}],
proxy: {
type: 'localstorage',
id: 'calendar-app-store'
},
data: [
{ id: 1, title: 'January', image: 'jan.iPNG'}
, { id: 2, title: 'Febuary'}
, { id: 3, title: 'March'}
, { id: 4, title: 'April'}
, { id: 5, title: 'May'}
, { id: 6, title: 'June'}
, { id: 7, title: 'July'}
, { id: 8, title: 'August'}
, { id: 9, title: 'September'}
, { id: 10, title: 'October'}
, { id: 11, title: 'November'}
, { id: 12, title: 'December'}
]
});`
and i am trying to load image i.e 'jan.iPNG' which i have in store and source changes with month.i am able to display month name from {title} but not from {image}.All i get is a ?mark on the app.
I read that if i get ? mark then the src path is incorrect but if i give
'html : '<img style="height: 700px; width: 500px;" src="jan.iPNG "/>' '
it displays fine.
below is the view
'CalendarApp.views.viewCalendar = new Ext.form.FormPanel({
id: 'viewCalendar',
scroll: 'true',
items:[{
xtype: 'textfield',
name: 'title'
// label: 'title'
},
{
xtype: 'panel',
name :'image',
html : '<img style="height: 700px; width: 500px;" src="{image}"/>'
}],
dockedItems:[CalendarApp.views.calTopToolbar]
});'
First save the image in custom folder where your files are present.
and use below code,
{
xtype: 'panel',
icon: 'jan.png', // specify the path of the image
width:100, // if u want to specify the width for image
height:80, // if u want to specify the height for image
iconMask: false,
handler: jan // if u want to handle the click event
}
another option is u can define the image in html file by
<style>
.NewIcon {
-webkit-mask-box-image: url('../img/new_icon.png');
}
</style>
and specify this New icon in the js file where you want to use it
{
xtype: 'panel',
iconCls: 'NewIcon ',
width:100,
height:80,
iconMask: false,
handler: newicon
}