why the use of mobx caused the onChange of the table twice? - mobx

The first click on the page number will only trigger onChange once, and then click the page number will trigger twice.
codesandbox: https://codesandbox.io/s/late-shape-mznvvf?file=/demo.tsx
import "#arco-design/web-react/dist/css/arco.css";
import React from "react";
import { Table, TableColumnProps } from "#arco-design/web-react";
import { makeAutoObservable, runInAction } from "mobx";
import { observer } from "mobx-react";
class P {
pagination = {
current: 1,
pageSize: 2
};
constructor() {
makeAutoObservable(this, {
onChange: false
});
}
onChange(pagination) {
runInAction(() => {
this.pagination = pagination;
})
console.log("exec!");
}
}
const columns: TableColumnProps[] = [
{
title: "Name",
dataIndex: "name"
},
{
title: "Salary",
dataIndex: "salary"
},
{
title: "Address",
dataIndex: "address"
},
{
title: "Email",
dataIndex: "email"
}
];
const data = [
{
key: "1",
name: "Jane Doe",
salary: 23000,
address: "32 Park Road, London",
email: "jane.doe#example.com"
},
{
key: "2",
name: "Alisa Ross",
salary: 25000,
address: "35 Park Road, London",
email: "alisa.ross#example.com"
},
{
key: "3",
name: "Kevin Sandra",
salary: 22000,
address: "31 Park Road, London",
email: "kevin.sandra#example.com"
},
{
key: "4",
name: "Ed Hellen",
salary: 17000,
address: "42 Park Road, London",
email: "ed.hellen#example.com"
},
{
key: "5",
name: "William Smith",
salary: 27000,
address: "62 Park Road, London",
email: "william.smith#example.com"
},
{
key: "6",
name: "Jane Doe",
salary: 23000,
address: "32 Park Road, London",
email: "jane.doe#example.com"
},
{
key: "7",
name: "Alisa Ross",
salary: 25000,
address: "35 Park Road, London",
email: "alisa.ross#example.com"
},
{
key: "8",
name: "Kevin Sandra",
salary: 22000,
address: "31 Park Road, London",
email: "kevin.sandra#example.com"
},
{
key: "9",
name: "Ed Hellen",
salary: 17000,
address: "42 Park Road, London",
email: "ed.hellen#example.com"
},
{
key: "10",
name: "William Smith",
salary: 27000,
address: "62 Park Road, London",
email: "william.smith#example.com"
}
];
const application = new P();
const App = observer(() => {
return (
<Table
pagination={application.pagination}
columns={columns}
data={data}
onChange={(pagination) => application.onChange(pagination)}
/>
);
});
export default App;
why the use of mobx caused the onChange of the table twice?
know why the use of mobx caused the onChange of the table twice?

Related

VueJS errors when using external components

Let me preface this by saying that I'm new to VueJS and I expect the solution to my problem is something trivial but I can't for the life of me figure it out or find it online so here I am :
I followed Traversy Media's crash course on VueJS and built the task tracker app alongside him and everything was working well. But after the course ended, I decided to play around with Data Tables in the About page, specifically, using tables that have column filtering. Two candidates came up : VueGoodTable and VueBootstrap4Table.
I know for a fact that VueGoodTable works because I had already used it before with Laravel without really understanding how any of it works, but when I tried to import it here, I kept getting this error :
Code:
<template>
<div class="about">
<h1>This is an about page</h1>
<vue-good-table
:columns="columns"
:rows="rows"/>
</div>
</template>
<script>
import 'vue-good-table/dist/vue-good-table.css'
import { VueGoodTable } from 'vue-good-table';
export default {
components: {
VueGoodTable,
},
data(){
return {
columns: [
{
label: 'Name',
field: 'name',
},
{
label: 'Age',
field: 'age',
type: 'number',
},
{
label: 'Created On',
field: 'createdAt',
type: 'date',
dateInputFormat: 'yyyy-MM-dd',
dateOutputFormat: 'MMM do yy',
},
{
label: 'Percent',
field: 'score',
type: 'percentage',
},
],
rows: [
{ id:1, name:"John", age: 20, createdAt: '',score: 0.03343 },
{ id:2, name:"Jane", age: 24, createdAt: '2011-10-31', score: 0.03343 },
{ id:3, name:"Susan", age: 16, createdAt: '2011-10-30', score: 0.03343 },
{ id:4, name:"Chris", age: 55, createdAt: '2011-10-11', score: 0.03343 },
{ id:5, name:"Dan", age: 40, createdAt: '2011-10-21', score: 0.03343 },
{ id:6, name:"John", age: 20, createdAt: '2011-10-31', score: 0.03343 },
],
};
},
}
</script>
This code is literally copy-pasted from the Get Started page of the VueGoodTable documentation.
A different error also happens when I try to use VueBootstrap4Table instead :
Code:
<template>
<div class="about">
<h1>This is an about page</h1>
<vue-bootstrap4-table :rows="rows" :columns="columns" :config="config">
</vue-bootstrap4-table>
</div>
</template>
<script>
import VueBootstrap4Table from 'vue-bootstrap4-table'
export default {
data: function() {
return {
rows: [{
"id": 1,
"name": {
"first_name": "Vladimir",
"last_name": "Nitzsche"
},
"address": {
"country": "Mayotte"
},
"email": "franecki.anastasia#gmail.com",
},
{
"id": 2,
"name": {
"first_name": "Irwin",
"last_name": "Bayer"
},
"age": 23,
"address": {
"country": "Guernsey"
},
"email": "rlittle#macejkovic.biz",
},
{
"id": 3,
"name": {
"first_name": "Don",
"last_name": "Herman"
},
"address": {
"country": "Papua New Guinea"
},
"email": "delia.becker#cormier.com",
}],
columns: [{
label: "id",
name: "id",
filter: {
type: "simple",
placeholder: "id"
},
sort: true,
},
{
label: "First Name",
name: "name.first_name",
filter: {
type: "simple",
placeholder: "Enter first name"
},
sort: true,
},
{
label: "Email",
name: "email",
sort: true,
},
{
label: "Country",
name: "address.country",
filter: {
type: "simple",
placeholder: "Enter country"
},
}],
config: {
checkbox_rows: true,
rows_selectable: true,
card_title: "Vue Bootsrap 4 advanced table"
}
}
},
components: {
VueBootstrap4Table
}
}
</script>
I'm guessing that I'm not importing these components correctly somehow, so I would appreciate any help with this.
Thank you.
The unfortunate fact is that "not so recent" release of Vue v3 has bring some breaking changes from Vue 2 which require some migration
It is safe to say that very little of the existing components and component libraries created for Vue 2 work without any modification in Vue 3
The repo linked to the course shows that you are using Vue 3. But Both the vue-good-table or vue-bootstrap4-table are Vue 2 components and do not have a version for Vue 3 yet
So you need to look for different component and look for explicit support of Vue 3...

GraphQLObjectType is not a constructor

I'm trying to follow a graphql tutorial, even thoughg I followed it and double checked I keep getting the above error and I have no idea why
dont you really hate when the bot asks you to type more, its mostly code for a reason I dont have a clue and I posted all my code!!!
const express = require("express");
const expressGraphQL = require("express-graphql");
const graphql = require("graphql");
const {
GraphQlSchema,
GraphQlObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLNonNull,
} = graphql;
const app = express();
const authors = [
{ id: 1, name: "J. K. Rowling" },
{ id: 2, name: "J. R. R. Tolkien" },
{ id: 3, name: "Brent Weeks" },
];
const books = [
{ id: 1, name: "Harry Potter and the Chamber of Secrets", authorId: 1 },
{ id: 2, name: "Harry Potter and the Prisoner of Azkaban", authorId: 1 },
{ id: 3, name: "Harry Potter and the Goblet of Fire", authorId: 1 },
{ id: 4, name: "The Fellowship of the Ring", authorId: 2 },
{ id: 5, name: "The Two Towers", authorId: 2 },
{ id: 6, name: "The Return of the King", authorId: 2 },
{ id: 7, name: "The Way of Shadows", authorId: 3 },
{ id: 8, name: "Beyond the Shadows", authorId: 3 },
];
const BookType = new GraphQlObjectType({
name: "Book",
description: "A Book written by an author",
fields: () => ({
id: { type: GraphQLNonNull(GraphQLInt) },
name: { type: GraphQLNonNull(GraphQLString) },
authorId: { type: GraphQLNonNull(GraphQLInt) },
}),
});
const RouteQueryType = new GraphQlObjectType({
name: "Query",
description: "Root Query",
fields: () => ({
books: new GraphQLList(BookType),
description: "List of Books",
resolve: () => books,
}),
});
const schema = new GraphQlSchema({
query: RouteQueryType,
});
app.use(
"/graphql",
expressGraphQL({
schema: schema,
graphiql: true,
})
);
app.listen(5000, () => console.log("server running"));
Wrong capitilisation GraphQlObjectType should be GraphQLObjectType

Dynamically display table column/row with data that contains different size of nested array?

I'm trying to display the data that I took from firestore and want to display it on a table using Vue.js and Element UI. I've tried looking for a solution but most shows for fixed amount of data whilst for my case I have an uneven number of data.
The structure of my data are as follows:
suppData: [{
comp_name: "company 1",
country: "country 1",
contInfo: [{
cpName: "John Doe",
phone: "123123",
email: "john#doe.com
},
prodList: [{
product: "eggs",
product: "shoes"
}
}],
comp_name: "company 2",
country: "country 2",
contInfo: [{
cpName: "Jack Doe",
phone: "1231231",
email: "jack#doe.com
},
{
cpName: "Michelle",
phone: "12412",
email: "mmichelle#doe.com
},
prodList: [{
product: "eggs",
}
}]
}]
The code I'm using for the table right now, played around with other methods such as formatter, flattening the data, but can't get it to work so help is appreciated!
<el-table-column label="Company Name" prop="company_name"></el-table-column>
<el-table-column label="Country" prop="country"></el-table-column>
<el-table-column label="Contacs" prop="contactName.cpName"></el-table-column>
For adding a row you just have to add an entry to your dataset. For columns you could create a seperate array with column data. You could manage this array yourself. This is an example how you could achieve it:
HTML:
<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column v-for="item in tableStructure" :key="item.prop" prop="item.prop" :label="item.label"></el-table-column>
</el-table>
<el-button #click="addRow">Add row</el-button>
<el-button #click="addColumn">Add column</el-button>
</template>
JS:
data() {
return {
tableStructure: [
{ label: "date", prop:"date" },
{ label: "name", prop:"name" }
],
tableData: [{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
},
methods: {
addRow() {
this.tableData.push({
date: '2021-001-01',
name: 'New row',
address: 'Other address'
})
},
addColumn() {
this.tableStructure.push({ label: "address", prop:"address" })
}
}
}
Here is the example in codepen: https://codepen.io/reijnemans/pen/mdrOXgZ?editors=1011

How to implement Groupping in Nativescript Vue RadDataForm?

Want to use Fields grouping Documention is not prvided event the topic of grouping nor the example. Most of the example are using typescript. Event the Google is not showing the result.
<RadDataForm
ref="dataform"
:source="customerForm"
:metadata="customerFormMetadata"
:groups="groups"
/>
customerFormMetadata: {
isReadOnly: false,
commitMode: "Immediate",
validationMode: "Immediate",
propertyAnnotations: [
{
name: "customer_name_1",
displayName: "Customer Name",
index: 0,
groupName: "Personal",
editor: "Text"
},
groups: [
Object.assign(new PropertyGroup(), {
name: "Personal",
collapsible: true,
collapsed: false
}),
Object.assign(new PropertyGroup(), {
name: "Address",
collapsible: true,
collapsed: true
})
],
Grouping doesn't require any addtional configuration while using with Vue, it's pretty straight forward as described in the core docs.
Example
<template>
<Page class="page">
<ActionBar title="Home" class="action-bar" />
<RadDataForm :source="person" :metadata="groupMetaData" />
</Page>
</template>
<script>
import Vue from "nativescript-vue";
import RadDataForm from "nativescript-ui-dataform/vue";
Vue.use(RadDataForm);
export default {
data() {
return {
person: {
name: "John",
age: 23,
email: "john#company.com",
city: "New York",
street: "5th Avenue",
streetNumber: 11
},
groupMetaData: {
propertyAnnotations: [{
name: "city",
index: 3,
groupName: "Address",
editor: "Picker",
valuesProvider: [
"New York",
"Washington",
"Los Angeles"
]
},
{
name: "street",
index: 4,
groupName: "Address"
},
{
name: "streetNumber",
index: 5,
editor: "Number",
groupName: "Address"
},
{
name: "age",
index: 1,
editor: "Number",
groupName: "Main Info"
},
{
name: "email",
index: 2,
editor: "Email",
groupName: "Main Info"
},
{
name: "name",
index: 0,
groupName: "Main Info"
}
]
}
};
}
};
</script>
Edit:
As discussed in the docs, to make the Group collapsible use the groupUpdate event.
onGroupUpdate: function(args) {
let nativeGroup = args.group;
if (args.ios) {
nativeGroup.collapsible = true;
} else {
nativeGroup.setExpandable(true);
}
}
Updated Playground

How can I allocate different ID or class to my list item?

First, I apologize for my poor English.
I am trying to build a list where each item has a different ID or class, because I want to control which items are displayed (hidden or visible).
Can anyone help?
I will be grateful!
Ext.define('Contact', {
extend: 'Ext.data.Model',
config: {
fields: ['firstName', 'lastName']
}
});
var store = Ext.create('Ext.data.Store', {
model: 'Contact',
sorters: 'lastName',
data: [
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Rob', lastName: 'Dougan' },
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Jamie', lastName: 'Avins' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Dave', lastName: 'Kaneda' },
{ firstName: 'Jacky', lastName: 'Nguyen' },
{ firstName: 'Abraham', lastName: 'Elias' },
{ firstName: 'Jay', lastName: 'Robinson'},
{ firstName: 'Nigel', lastName: 'White' },
{ firstName: 'Don', lastName: 'Griffin' },
{ firstName: 'Nico', lastName: 'Ferrero' },
{ firstName: 'Nicolas', lastName: 'Belmonte'},
{ firstName: 'Jason', lastName: 'Johnston'}
]
});
Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '<div class="contact custom_class_{firstName}">{firstName} <strong>{lastName}</strong></div>',
store: store
});
by using above code you can add custom css classes to every item in list view, just specify custom_class_{uniqueid of model} for every node and then you can access it using Ext.DomQuery.select('div{class=contact custom_class_{firstName}}'); and then you traverse the DOM to get the parent element which you can use it to hide list item
var div = Ext.DomQuery.select('div{class=contact custom_class_{firstName}}');
var listItem = div.up().up();