How to merge two input cells in table with ReactJs like an Excel












0















I would like to create a table in ReactJs which has inputs instead of data cells like a small Excel project. But I have created the table in the following link. And now, I want to merge two inputs when they are chosen with the help of button and pressed. I have no idea to start this merging inputs. If you have any clue to start this one, can you let me know. Otherwise I am surfing the whole Internet to find any project like it but no result yet.



<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>

class App extends React.Component {
constructor(props) {
super(props);
this.state = {
users: [{code:"", id: "", data: "", others: "", something: ""}]
};
}

addClick(){
this.setState(prevState => ({
users: [...prevState.users, { others: "", something: "", code: "", id: "",
data: "" }]
}))
}

createUI(){
return this.state.users.map((el, i) => (
<tbody key={i}>
<tr>
<td>
<input type='text' placeholder={i+1} name="something" value=
{el.something ||''} onChange={this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="code" name="code" value={el.code ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="id" name="id" value={el.id ||''} onChange=
{this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="Data" name="data" value={el.data ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="Others..." name="others" value={el.others ||''}
onChange={this.handleChange.bind(this, i)} />
</td>
</tr>
</tbody>
))
}

handleChange(i, e) {
const { name, value } = e.target;
let users = [...this.state.users];
users[i] = {...users[i], [name]: value};
this.setState({ users });
}

removeClick(){
let users = [...this.state.users];
users.pop();
this.setState({ users });
}



render() {
return (
<div>
<button onClick={this.addClick.bind(this)}>+</button>
<button onClick={this.removeClick.bind(this)}>Remove</button>
<button>Drag</button>
<table>
<thead>
<tr>
<th>Something</th>
<th>Code</th>
<th> ID </th>
<th> Data</th>
<th>Others</th>
</tr>
</thead>
{this.createUI()}
</table>
</div>
);
}
}

ReactDOM.render(<App />, document.getElementById('container'));









share|improve this question

























  • Can you expand more on what you mean by merging two inputs when a button is pressed?

    – Tall Paul
    Nov 24 '18 at 19:27
















0















I would like to create a table in ReactJs which has inputs instead of data cells like a small Excel project. But I have created the table in the following link. And now, I want to merge two inputs when they are chosen with the help of button and pressed. I have no idea to start this merging inputs. If you have any clue to start this one, can you let me know. Otherwise I am surfing the whole Internet to find any project like it but no result yet.



<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>

class App extends React.Component {
constructor(props) {
super(props);
this.state = {
users: [{code:"", id: "", data: "", others: "", something: ""}]
};
}

addClick(){
this.setState(prevState => ({
users: [...prevState.users, { others: "", something: "", code: "", id: "",
data: "" }]
}))
}

createUI(){
return this.state.users.map((el, i) => (
<tbody key={i}>
<tr>
<td>
<input type='text' placeholder={i+1} name="something" value=
{el.something ||''} onChange={this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="code" name="code" value={el.code ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="id" name="id" value={el.id ||''} onChange=
{this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="Data" name="data" value={el.data ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="Others..." name="others" value={el.others ||''}
onChange={this.handleChange.bind(this, i)} />
</td>
</tr>
</tbody>
))
}

handleChange(i, e) {
const { name, value } = e.target;
let users = [...this.state.users];
users[i] = {...users[i], [name]: value};
this.setState({ users });
}

removeClick(){
let users = [...this.state.users];
users.pop();
this.setState({ users });
}



render() {
return (
<div>
<button onClick={this.addClick.bind(this)}>+</button>
<button onClick={this.removeClick.bind(this)}>Remove</button>
<button>Drag</button>
<table>
<thead>
<tr>
<th>Something</th>
<th>Code</th>
<th> ID </th>
<th> Data</th>
<th>Others</th>
</tr>
</thead>
{this.createUI()}
</table>
</div>
);
}
}

ReactDOM.render(<App />, document.getElementById('container'));









share|improve this question

























  • Can you expand more on what you mean by merging two inputs when a button is pressed?

    – Tall Paul
    Nov 24 '18 at 19:27














0












0








0








I would like to create a table in ReactJs which has inputs instead of data cells like a small Excel project. But I have created the table in the following link. And now, I want to merge two inputs when they are chosen with the help of button and pressed. I have no idea to start this merging inputs. If you have any clue to start this one, can you let me know. Otherwise I am surfing the whole Internet to find any project like it but no result yet.



<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>

class App extends React.Component {
constructor(props) {
super(props);
this.state = {
users: [{code:"", id: "", data: "", others: "", something: ""}]
};
}

addClick(){
this.setState(prevState => ({
users: [...prevState.users, { others: "", something: "", code: "", id: "",
data: "" }]
}))
}

createUI(){
return this.state.users.map((el, i) => (
<tbody key={i}>
<tr>
<td>
<input type='text' placeholder={i+1} name="something" value=
{el.something ||''} onChange={this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="code" name="code" value={el.code ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="id" name="id" value={el.id ||''} onChange=
{this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="Data" name="data" value={el.data ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="Others..." name="others" value={el.others ||''}
onChange={this.handleChange.bind(this, i)} />
</td>
</tr>
</tbody>
))
}

handleChange(i, e) {
const { name, value } = e.target;
let users = [...this.state.users];
users[i] = {...users[i], [name]: value};
this.setState({ users });
}

removeClick(){
let users = [...this.state.users];
users.pop();
this.setState({ users });
}



render() {
return (
<div>
<button onClick={this.addClick.bind(this)}>+</button>
<button onClick={this.removeClick.bind(this)}>Remove</button>
<button>Drag</button>
<table>
<thead>
<tr>
<th>Something</th>
<th>Code</th>
<th> ID </th>
<th> Data</th>
<th>Others</th>
</tr>
</thead>
{this.createUI()}
</table>
</div>
);
}
}

ReactDOM.render(<App />, document.getElementById('container'));









share|improve this question
















I would like to create a table in ReactJs which has inputs instead of data cells like a small Excel project. But I have created the table in the following link. And now, I want to merge two inputs when they are chosen with the help of button and pressed. I have no idea to start this merging inputs. If you have any clue to start this one, can you let me know. Otherwise I am surfing the whole Internet to find any project like it but no result yet.



<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>

class App extends React.Component {
constructor(props) {
super(props);
this.state = {
users: [{code:"", id: "", data: "", others: "", something: ""}]
};
}

addClick(){
this.setState(prevState => ({
users: [...prevState.users, { others: "", something: "", code: "", id: "",
data: "" }]
}))
}

createUI(){
return this.state.users.map((el, i) => (
<tbody key={i}>
<tr>
<td>
<input type='text' placeholder={i+1} name="something" value=
{el.something ||''} onChange={this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="code" name="code" value={el.code ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="id" name="id" value={el.id ||''} onChange=
{this.handleChange.bind(this, i)} />
</td>
<td>
<input placeholder="Data" name="data" value={el.data ||''} onChange=
{this.handleChange.bind(this, i)} /></td>
<td>
<input placeholder="Others..." name="others" value={el.others ||''}
onChange={this.handleChange.bind(this, i)} />
</td>
</tr>
</tbody>
))
}

handleChange(i, e) {
const { name, value } = e.target;
let users = [...this.state.users];
users[i] = {...users[i], [name]: value};
this.setState({ users });
}

removeClick(){
let users = [...this.state.users];
users.pop();
this.setState({ users });
}



render() {
return (
<div>
<button onClick={this.addClick.bind(this)}>+</button>
<button onClick={this.removeClick.bind(this)}>Remove</button>
<button>Drag</button>
<table>
<thead>
<tr>
<th>Something</th>
<th>Code</th>
<th> ID </th>
<th> Data</th>
<th>Others</th>
</tr>
</thead>
{this.createUI()}
</table>
</div>
);
}
}

ReactDOM.render(<App />, document.getElementById('container'));






reactjs html-table






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 23:20









Brian Tompsett - 汤莱恩

4,2331338101




4,2331338101










asked Nov 24 '18 at 17:44









Izzatullo KanoatovIzzatullo Kanoatov

135




135













  • Can you expand more on what you mean by merging two inputs when a button is pressed?

    – Tall Paul
    Nov 24 '18 at 19:27



















  • Can you expand more on what you mean by merging two inputs when a button is pressed?

    – Tall Paul
    Nov 24 '18 at 19:27

















Can you expand more on what you mean by merging two inputs when a button is pressed?

– Tall Paul
Nov 24 '18 at 19:27





Can you expand more on what you mean by merging two inputs when a button is pressed?

– Tall Paul
Nov 24 '18 at 19:27












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460830%2fhow-to-merge-two-input-cells-in-table-with-reactjs-like-an-excel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460830%2fhow-to-merge-two-input-cells-in-table-with-reactjs-like-an-excel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin