Update table without database

Update table without database

schnoedeltroedelschnoedeltroedel Posts: 1Questions: 1Answers: 0

In https://datatables.net/forums/discussion/36014/is-it-possible-to-use-editor-without-a-backend-database you mentioned that in v 1.6 we will be able to edit the table without any extra configuration. I'm not able to figure out how this works.
I have a json file from which I'm loading all my data. I removed the ajax property from the Editor as described in your example page https://editor.datatables.net/examples/simple/noAjax.html.
Now when I change somethin in my table. Nothing happens.
If I change something in your example site, the table is updated magically :wink:

Here's my simplified code:

var editor = new $.fn.dataTable.Editor({
    idSrc: 'nummer',
    table: '#example',
    fields: fields,
    formOptions: {
        bubble: {
            title: 'Edit',
            buttons: false
        }
    }
});

I dynamically generate the fields by pushing objects into an array, e.g.

[
    {name: "str", label: "Straße", type: "text"},
    {name: "hnr", label: "Hausnummer", type: "text"},
    {name: "plz", label: "Postleitzahl", type: "text"}
]

I then create the DataTable:

$('#example').DataTable({
    ajax: "data.json",
    dom: "Bfrtip",
    columns: columns,
    paging: false,
    select: true,
    buttons: [
        { extend: "create", editor: editor },
        { extend: "edit", editor: editor },
        { extend: "remove", editor: editor },
    ],
    fixedHeader: true,
    columnDefs: columnDefs,
});

I also generate columns dynamically, e.g.:

[
    {data: null, defaultContent: "", className: "select-checkbox", orderable: false, bSortable: false, mData: null, sClass: "select-checkbox", sDefaultContent: ""},  // to get checkboxes in first column
    {data: "str", mData: "strasse"},
    {data: "hnr", mData: "hausnummer"},
    {data: "plz", mData: "postleitzahl"}
]

Maybe worth mentioning, that I didn't create mData or sClass, bSortable or sDefaultContent parameters, but they are there...

Please lead me in the right direction. Do I need to install some php libs as mentioned in the install section of the manual. I just thought this is not necessary if I'm not using a database connection.

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Can you give me a link to your page so I can take a look and see what is going wrong please? There is no need to use a PHP library - the example you mention shows Editor working automatically on the client-side.

    Thanks,
    Allan

This discussion has been closed.