cannot read property 'length'

cannot read property 'length'

TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

I am troubleshooting the property length error and I can't quite figure it out.
My code works by emulating using an objects.txt file that has the json response, but I have to change "value" to "data" in the objects.txt and in the dataSrc
otherwise it gives me the property 'length' error.

Working:
*/
$(document).ready(function() {
$('#ReadyList').DataTable( {
"ajax": "objects.txt",
"dataSrc": "data",
"columns": [
{ "data": "UD01_Number02" },
{ "data": "OrderDtl_XPartNum" },
{ "data": "OrderDtl_NeedByDate" },
{ "data": "OrderHed_PONum" },
{ "data": "UD01_Number01" },
{ "data": "UD01_Number04" },
{ "data": "UD01_Number03" },
{ "data": "JobProd_JobNum" },
{ "data": "OrderDtl_LineDesc" },
{ "data": "OrderHed_ShipToNum" },
{ "data": "Calculated_BundleAge" },
{ "data": "Calculated_SamplePending" },
{"data": "RowIdent"},

  ]

} );

Not Working I also change data to value in the objects.txt that I am testing with.

$(document).ready(function() {
$('#ReadyList').DataTable( {
"ajax": "objects.txt",
"dataSrc": "value",
"columns": [
{ "value": "UD01_Number02" },
{ "value": "OrderDtl_XPartNum" },
{ "value": "OrderDtl_NeedByDate" },
{ "value": "OrderHed_PONum" },
{ "value": "UD01_Number01" },
{ "value": "UD01_Number04" },
{ "value": "UD01_Number03" },
{ "value": "JobProd_JobNum" },
{ "value": "OrderDtl_LineDesc" },
{ "value": "OrderHed_ShipToNum" },
{ "value": "Calculated_BundleAge" },
{ "value": "Calculated_SamplePending" },
{"value": "RowIdent"},

  ]

} );

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,308Questions: 26Answers: 4,769

    "ajax": "objects.txt",
    "dataSrc": "data",

    The option is ajax.dataSrc. If you want to use it then you need to place it inside the ajax config option by making it an object. Looks something like this:

    "ajax": {
        "url": "objects.txt",
        "dataSrc": "data",
    },
    

    But using "dataSrc": "data" is the same as the default so its not needed. Is you data returned in an object named value?

    With objects you will use columns.data, similar to your first snippet. There is not an option of columns.value. The Datatables options are documented here:
    https://datatables.net/reference/option/

    I'm not sure what exactly you need to configure. Please post a snippet of your objects.txt so we can see the structure you have.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    This is the response that is in the objects.txt

    {
    "odata.metadata": "https://erp10/ERP102500/api/v1/BaqSvc/66457-ReadyListCust/$metadata#Epicor.DynamicQuery.QueryResults",
    "value": [
    {
    "UD01_Number02": "289.000000000",
    "OrderDtl_XPartNum": "01-06-0096",
    "OrderDtl_NeedByDate": "2020-04-20T00:00:00",
    "OrderHed_PONum": "54305",
    "UD01_Number01": "26.750000000",
    "UD01_Number04": "452.248875000",
    "UD01_Number03": "644.230000000",
    "JobProd_JobNum": "102973-3-1",
    "OrderDtl_LineDesc": ".875\"X14GA HRPO MT1010 GCDB",
    "OrderHed_ShipToNum": "LEMP",
    "Calculated_BundleAge": 14,
    "Calculated_SamplePending": false,
    "RowIdent": "2184b359-acea-4f34-98c8-78c072a17d2c"
    }

  • kthorngrenkthorngren Posts: 20,308Questions: 26Answers: 4,769

    Try this:

    $('#ReadyList').DataTable( {
      "ajax": {
          "url": "objects.txt",
          "dataSrc": "data",
      },
      "columns": [
          { "data": "UD01_Number02" },
          { "data": "OrderDtl_XPartNum" },
          { "data": "OrderDtl_NeedByDate" },
          { "data": "OrderHed_PONum" },
          { "data": "UD01_Number01" },
          { "data": "UD01_Number04" },
          { "data": "UD01_Number03" },
          { "data": "JobProd_JobNum" },
          { "data": "OrderDtl_LineDesc" },
          { "data": "OrderHed_ShipToNum" },
          { "data": "Calculated_BundleAge" },
          { "data": "Calculated_SamplePending" },
          {"data": "RowIdent"},
      ]
    });
    

    Assuming your HTML table has 13 columns then you should be good.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    HTML is correct. dataSrc data does not work because the object is value not data, but it will error out with value but works if I replace with data in both locations

  • kthorngrenkthorngren Posts: 20,308Questions: 26Answers: 4,769
    Answer ✓

    Sorry, copy/paste error. It should be "dataSrc": "value", with columns.data. Like this:

    $('#ReadyList').DataTable( {
      "ajax": {
          "url": "objects.txt",
          "dataSrc": "value",
      },
      "columns": [
          { "data": "UD01_Number02" },
    ...
          {"data": "RowIdent"},
      ]
    });
    

    Are you saying this doesn't work?

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    A copy and past of your code and it is working. Perfect! Thank you. I must have had syntax wrong somewhere. the value is now pulling the data correctly into the datatable.

This discussion has been closed.