Switching between tables for data

Switching between tables for data

test42test42 Posts: 21Questions: 8Answers: 0

Hi,

I've built out my app that dynamically loads CSV datasets and redraws the table based on dropdown, works great. Now I want to convert it to use the editor and database so I can have multiple users go in and edit/save different datasets.

If I have 10 sets of data, do I need to create 10 tables and then call the API to switch between them (with them all sharing the same schema)? I was confused because it seems like the editor just works with one table to do all the editing. Trying to understand it from an architecture point of view.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Essentially yes, that is what you would need to do. Are the data sets completely different from each other (e.g. a file of "passengers", one of "cars", one of "parts", etc). Or are they all basically the same but contain different data?

    Allan

  • test42test42 Posts: 21Questions: 8Answers: 0

    Hey Allan,

    They're all the same, essentially we're exporting a list of every department's documents to be reviewed for migration, and then give them the opportunity for users to select their department and add predefined meta deta. In this case all the headers would be identical with just the data changing when you select marketing vs accounting.

    If I'm going to be generating a lot of rendered columns, should I stick with client side vs server side processing as I'll need to send that data back to the database. And in that case, would it be best to use the API to handle that updating to the DB?

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    If they are all the same I'd be tempted to reuse the same table. clear() to clear out the old data and then rows.add() to add the new ones from wherever they are (ajax?).

    Server-side processing is a performance decision for the amount of data. Typically I would say for a table with 5-10 columns and >50'000 rows, then use server-side processing. DataTables doesn't attempt to do any kind of virtual rendering for columns, so there isn't a huge amount of performance gain by switching to server-side processing earlier. It really depends on the amount of data and the time take to transmit, read and render that.

    Regards,
    Allan

  • test42test42 Posts: 21Questions: 8Answers: 0
    edited August 2018

    I'll probably stick with client side then. I was planning on redrawing the same table using those functions, this was my old code using CSV I think I can resuse;

    $('#reportSelect').on('change', function() {
            var reportSelected = this.value;
            reportSelected = reportSelected.toLowerCase();       
            $('#reportSelect').find('option:contains("' + reportSelected + '")').attr("selected", true);
            loadData(reportSelected);
        });
    
        //load json from that dynamically
        function loadData(d) {
            var myURL = "./php/json/" + d;
            $.getJSON(myURL, function(data) {
                //reloading table data - should warn user to save data
                $('#example').DataTable().clear().rows.add(data).draw();
    
            });
        }
    

    So in this case, would I just want to create the 10 tables with the same structure, and then when it's passed into the existing datatable, the datatable is smart enough to understand which table was loaded and apply the edits/saves to that table?

    Should I continue to initialize the data in the datatables config using "data: xxx" or is there a better way with data pulled from MySQL?

    Thanks for all your help!

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Answer ✓

    the datatable is smart enough to understand which table was loaded and apply the edits/saves to that table?

    No - you'd need to trigger any saved via the API methods or Ajax calls depending on exactly where you want to save the data.

    Should I continue to initialize the data in the datatables config using "data: xxx" or is there a better way with data pulled from MySQL?

    You can either use data or have DataTables load the data for you via Ajax with ajax (the latter has the benefit of then allowing the use of ajax.reload() to be used). The fact that it is a MySQL database is actually irrelevant to DataTables itself.

    Allan

This discussion has been closed.