Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82115

Editor fields data problem

$
0
0

Hello,

I'm facing a small problem with the fields object when initializing the editor.

 dataEditor = new editor({
        ajax:   "/endpoint",
        table: '#' + targetDiv + "-table",
        idSrc: "0",
        fields
    });

Atm fields are like this:

name: 0,
type:text

name: 1,
type:text

name: 2,
type:text

This is due to the fact that I initialize the table this way:

 let options = {
        buttons: parsedButtons,
        data: parsedRows,
        columns: [0:{"title" : "firstname"}, 1:{"title": "lastname"}  2:{"title": "description"}],
        .....
}

$('#' + targetDiv + "-table").removeAttr('width').DataTable(options);

I do this because my data has the following format:

{
  "title" : "DATATABLE",
  "filter" : true,
  "columns" : [ {
    "editable" : false,
    "type" : "text",
    "title" : "firstname",
  }, {
    "editable" : false,
    "type" : "text",
    "title" : "lastname",
  }, {
    "editable" : false,
    "type" : "text",
    "title" : "description",
  }],
  "rows" : [ {
    "row" : [ {
      "text" : "Allan",
      "color" : null,
      "backgroundColor" : "#FFF"
    }, {
      "text" : "Jardine",
      "color" : "#000",
      "backgroundColor" : "#FFF"
    }, {
      "text" : "Business Owner",
      "color" : "#000",
      "backgroundColor" : "#FFF"
    } ]
}

But what I want to do is use names instead of numbers for the fields.

name: firstname,
type:text

name: lastname,
type:text

name: description,
type:text

And if I do this, I get the following error:

Uncaught Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11

I have also tried to add name parameter to columns but with no success.

Is there any easy way to achieve this?

Thanks in advance!


Viewing all articles
Browse latest Browse all 82115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>