Uncaught Error: Cannot automatically determine field name from data source

Uncaught Error: Cannot automatically determine field name from data source

Alex53Alex53 Posts: 13Questions: 4Answers: 0
edited November 2023 in Editor

Hi.
I try create editor and use it inline

Editor:

 var editor = new $.fn.dataTable.Editor( {
     idSrc: 'id',
    table: sensor_networks_table,
    fields: [
      { label: "order_id", name: "order_id" },
      { label: "year", name: "year"},
      { label: "month", name: "month"},
      { label: "week", name: "week"},
      { label: "id_dl_dt_zaezd_start", name: "id_dl_dt_zaezd_start"},
      { label: "id_dl_data_pokupki_kraski", name: "id_dl_data_pokupki_kraski"},
      { label: "dom", name: "dom"},
      { label: "id_dl_manager_project", name: "id_dl_manager_project"},
      { label: "manager_name", name: "manager_name"},
      { label: "contact_name",name: "contact_name"},
      { label: "address",name: "address"},
      { label: "project_name",name: "project_name"},
      { label: "opportunity",name: "opportunity"},
      { label: "prim",name: "prim"},
      { label: "team",name: "team"},
      {
        label:     "На базу",
        name:      "to_base",
        type:      "select",
        placeholder: 'На базу',
        separator: "|",
        options:   [
          { label: 'Да', value: 1 },
          { label: 'Нет', value: 0 }
        ]
      },
      { label: "dom_vyehal",name: "dom_vyehal"},
      { label: "stage_name",name: "stage_name"},
      { label: "furnishings",name: "furnishings"},
      { label: "project_stats",name: "project_stats"},
      { label: "smeta",name: "smeta"},
      { label: "ID", name: "id" },
    ]
  } );

Table:

var sensor_networks_table = $('#sensor_networks').DataTable({
    searchPanes: {
      viewTotal: true,
      initCollapsed: true,
      columns: [8]
    },
    dom: 'Bfrtip',
    language: languageRU,
    destroy: true,
    paging:          false,

    ajax: {
      url: $(this).data('url'),
      type: "GET",
    },
    columns: [
      { data: "order_id"},
      { data: "year"},
      { data: "month"},
      { data: "week"},
      { data: "id_dl_dt_zaezd_start"},
      { data: "id_dl_data_pokupki_kraski"},
      { data: "dom"},
      { data: "id_dl_manager_project"},
      { data: "manager_name"},
      { data: "contact_name"},
      { data: "address"},
      { data: "project_name"},
      { data: "opportunity"},
      { data: "prim"},
      { data: "team"},
      { data: "to_base"},
      { data: "dom_vyehal"},
      { data: "stage_name"},
      { data: "furnishings"},
      { data: "project_stats"},
      { data: "smeta"},
      { data: "id"},
    ],
    columnDefs: [
      { "visible": false, "targets": [1,2,3,21] },
      {
        orderable: false,

        searchPanes: {
          show: true,
          initCollapsed: true

        },
        targets: [8]
      },
      { className: "editable", targets: [15] },

    ],

    select: true,
    order: [[ 1, 'asc' ]],
    "drawCallback": function ( settings ) {
      var api = this.api();
      var rows = api.rows( {page:'current'} ).nodes();
      var last=null;
      var lastsub=null;
      var subgroup=null;
      var main_group=null;
      var month_counter = 0;
      var month_previous_record_count = 0;
      var group_counter = 0;

      api.column(1, {page:'current'} ).data().each( function ( group, i ) {
        if ( last !== group ) {
          $(rows).eq( i ).before(
              '<tr class="group"><td class="month-header-container-dt" colspan="20">'+group+'</td></tr>'
          );
          last = group;
        }
      });
      api.column(2, {page:'current'} ).data().each( function ( group, i ) {
        if ( last !== group ) {
          var group_tmp = group;
          $(rows).eq( i ).before(
              '<tr id="' + (month_counter + 1) + '" class="group month-group month-header-container-dt"><td colspan="20">'+group_tmp+'</td></tr>'
          );
          last = group;
          month_counter = month_counter + 1;

          if (i > 0) {
            group_counter = group_counter + 1;
            $("tr.month-group[id='" + (group_counter) + "'] td").append(' (Всего: ' + (i - month_previous_record_count) + ')');
            month_previous_record_count = i;
          }
          month_previous_record_count = i;
        }
        if (sensor_networks_table.data().count() == i+1) {
          $("tr.month-group[id='" + (group_counter + 1) + "'] td").append(' (Всего: ' + (sensor_networks_table.data().count() - month_previous_record_count) + ')');
        }
      });
      api.column(3, {page:'current'} ).data().each( function ( subgroup, i ) {
        moment.locale('ru');


        if ( lastsub !== subgroup && subgroup !== "" ) {
          var subgroup_html;

          var begin_date = moment().isoWeekday(1).isoWeekYear(sensor_networks_table.cell( i, 1 ).data()).isoWeek(sensor_networks_table.cell( i, 3 ).data()).toDate();
          var end_date = moment().isoWeekday(7).isoWeekYear(sensor_networks_table.cell( i, 1 ).data()).isoWeek(sensor_networks_table.cell( i, 3 ).data()).toDate();

          subgroup_html = '<tr class="subgroup"><td colspan="20">'+ 'НЕДЕЛЯ: ' + moment(begin_date).format('DD.MM.YYYY') + ' - ' + moment(end_date).format('DD.MM.YYYY') +'</td></tr>';

          $(rows).eq( i ).before(
              subgroup_html
          );
          lastsub = subgroup;
        }
      });
    }

  });

Inline:

sensor_networks_table.on( 'click', 'tbody td.editable', function (e) {
    editor.inline( sensor_networks_table.cell(this).index(), { onBlur: 'submit' } );
} );

What I'm doing wrong?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    The tech note that the error message links to has a fair amount of information on this.

    It basically means that the data option used for a column doesn't match a name for a field in Editor. I don't immediately see what column that would be though - they do appear to have a match.

    Can you give me a link to the page in question so I can debug it please?

    Thanks,
    Allan

  • Alex53Alex53 Posts: 13Questions: 4Answers: 0

    Hi,
    I cut some data fields for public link

    https://tinyurl.com/47c3vztu

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Thank you. The error might be here:

        // table: "#sensor_networks_table",
        table: sensor_networks_table,
    

    At that point sensor_networks_table is undefined - it is defined in the next block down as the DataTable.

    Could you comment out table: sensor_networks_table, and remove the comment from table: "#sensor_networks_table", please?

    Thanks,
    Allan

  • Alex53Alex53 Posts: 13Questions: 4Answers: 0

    Allan, thanks.
    No more error.
    My carelessness sent me in the wrong direction. Table id should be "#sensor_networks", not "#sensor_networks_table".

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Ah! That would do it.

    Good to know you got it working!

    Allan

Sign In or Register to comment.