olifolkerd / tabulator

Interactive Tables and Data Grids for JavaScript
http://tabulator.info
MIT License
6.76k stars 819 forks source link

Upload JSON file and reset data #1213

Closed simonwatz closed 6 years ago

simonwatz commented 6 years ago

Hi Oli,

I am trying to add and upload button to my page to select a file from your computer and reload the table.

I found this snippet to get started: https://jsfiddle.net/taditdash/9Fh4c/

This is what I have so far but I cannot seem to get the data to load?

function openfileDialog() {
                $("#fileLoader").click();
                $("#example-table").tabulator("destroy");
                LoadTable()
                $("#example-table").tabulator("setData", JSON.parse(this.jsonfile));
            }

            function LoadTable() {
                $("#example-table").tabulator({
                height:"60vh",
                layout:"fitColumns",
                tooltips:true,
                rowFormatter:function(row){
                    if((row.getData().Name).includes("Code")){
                        row.getElement().css({"background-color":"#A6A6DF"});
                    }
                },
                groupBy:"Name",
                columns:[
                {title:"Name", field:"Name", sorter:"string", editor:true},
                {title:"Path", field:"Path", sorter:"string", editor:true},
                {title:"RDP" , width:20, headerSort:false, formatter:openRDIcon, align:"center", cellClick:function(e, cell){alert("RDP Connection for: " + cell.getRow().getData().Name)}},
                {title:"VM" , width:20, headerSort:false, formatter:openVMIcon, align:"center", cellClick:function(e, cell){alert("VM Console for: " + cell.getRow().getData().Name)}},
                ],
            });

        }

        LoadTable()
        //Set initial page
        $("#example-table").tabulator("setPage", 1);

        $("#example-table").tabulator("setData", "/results1.json");

Could you please help with this? Thanks

olifolkerd commented 6 years ago

Hey @simonwatz

Why are you destroying the table and recreating it when you are loading in data? you could just call the setData function.

have you tried console logging the data you are trying to pass into the table to see if it is valid?

Cheers

Oli :)