Can editor work on json txt file as data source?

Can editor work on json txt file as data source?

YoDavishYoDavish Posts: 123Questions: 46Answers: 3
edited August 2022 in DataTables 1.9

We don't want to use a database for this since the information is very minimal. We have a txt file that contains json objects to load that datatables. I have that working, very similar to this URL below. Can we allow datatables editor to work with an json txt file as the data source where I can add new rows or edit existing ones?

https://datatables.net/examples/ajax/objects.html

Here is my code that includes the editor portion:

editor = new $.fn.dataTable.Editor({
    ajax: 'config_clientsVersion2.txt',
    table: "#table",
    fields: [ 
        {
            label: "G Number:",
            name: "gNumber"
        }, 
        {
            label: "Diagram Types:",
            name: "diagramTypes"
        },
        {
            label: "Require Gleason Score:",
            name: "showGleasonScore"
        },
        {
            label: "Require Percentage:",
            name: "showPercentage"
        },
    ]
});

$('#table').DataTable({
    dom: 'Bfrtip',
    ajax: 'config_clientsVersion2.txt',
    columns: [
        { data: 'gNumber' },
        { data: 'diagramTypes' },
        { data: 'showGleasonScore' },
        { data: 'showPercentage' }
    ],
    buttons: [
        { extend: "create", editor: editor },
        { extend: "edit",   editor: editor },
        { extend: "remove", editor: editor }
    ]
});

Answers

  • kthorngrenkthorngren Posts: 21,374Questions: 26Answers: 4,957

    You would need some sort of server functionality to update the file.

    Kevin

  • allanallan Posts: 63,569Questions: 1Answers: 10,481 Site admin

    Yes, as Kevin says, updating the JSON file would be up to the server-side, and that is not currently something that our Editor server-side libraries can do. They focus on SQL databases.

    So it is quite possible, it would just need the code for it to be written.

    Allan

Sign In or Register to comment.