Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update table for dynamic data #498

Closed
Swechhya opened this issue Jul 30, 2019 · 9 comments
Closed

Update table for dynamic data #498

Swechhya opened this issue Jul 30, 2019 · 9 comments

Comments

@Swechhya
Copy link

Is there a way to update the whole table including number of rows and columns, column headers etc. for dynamic data?

@pphod
Copy link
Contributor

pphod commented Jul 30, 2019

jexcel(domId, options)

You can save options and then use again later to recreate the table. To get options, you call xxx.getConfig()

@pphod pphod closed this as completed Jul 30, 2019
@Swechhya
Copy link
Author

The following is the code that I am using:

<html>
<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css" type="text/css" />

<script src="https://bossanova.uk/jtools/v2/japp.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jtools/v2/japp.css" type="text/css" />

<div id="spreadsheet"></div>

<script>
var data = [
    ['Mazda', 2001, 2000],
    ['Pegeout', 2010, 5000],
    ['Honda Fit', 2009, 3000],
    ['Honda CRV', 2010, 6000],
];


jexcel(document.getElementById('spreadsheet'), {
    data:data,
    columns:[
        { title:'Model', width:300 },
        { title:'Price', width:80 },
        { title:'Model', width:100 }
    ],
});
</script>
<input type='button' value='Update data' onclick="jexcel(document.getElementById('spreadsheet'),{
data: [
['A', 10],
['B', 20],
],
 columns:[
        { title:'Letter', width:300 },
        { title:'Number', width:80 }],
})">

</html>

On clicking the update data button, instead of the data being updated on the table I get two tables as follows:
Screen Shot 2019-07-30 at 18 06 26

@pphod
Copy link
Contributor

pphod commented Jul 30, 2019

Sure you must clear your table first. document.getElementById('spreadsheet').innerHTML = '';

@Swechhya
Copy link
Author

Actually, clearing the innerHTML and then updating the table would remove currently selected cell which from user perspective is slightly inconvenient. I was wondering if there was any method that could be called to update the table.

@pphod
Copy link
Contributor

pphod commented Jul 30, 2019 via email

@Swechhya
Copy link
Author

Swechhya commented Aug 2, 2019

Thanks @paulhodel , that's a great solution. I was hoping if there could be a function like setTable that would clear the replace the current table with a new table.

@pphod
Copy link
Contributor

pphod commented Aug 2, 2019

You don't need to change the whole table if you change only the data. For that you have setData.

Regards,

@shroffritesh
Copy link

Hi paul,
Is there any way, when we insert data into excel sheet that time data will store dynamically into :
jexcel(document.getElementById('spreadsheet'){
data : data , <------------------
}

@data-handler
Copy link

You don't need to change the whole table if you change only the data. For that you have setData.

Regards,

When I use setData to update an existing table instance, the correct number of columns and rows are rendered, but the cell contents are empty. I've tried the refresh method but same result. What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants