Requested unknown parameter

Requested unknown parameter

capcoincapcoin Posts: 6Questions: 2Answers: 0
edited September 2017 in Free community support

Hi,

I try to custom the display of a cell of my datatable:

  "render": function ( data, type, row ) {
    number_posts = parseInt(data);
    if(data > 0)
        return row[7];                          
   },

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    If the data is 0 then your function is returning undefined (since there is no explicit return statement for that case), which would result in the issue you are seeing. You need to return something.

    Allan

  • capcoincapcoin Posts: 6Questions: 2Answers: 0

    Sorry, I press Enter but the post is not complete./

    $(document).ready(function() {
      $('#data_index').DataTable({
        "ajax": 'data_index.php',
        "iDisplayLength": 100,
        "columnDefs": [{
          "render": function(data, type, row) {
            if (data > 0)
              return row[7] + "%";
          },
          "targets": [7]
        }]
      });
    });
    

    Here my JSON file:


    { "draw": 1, "recordsTotal": 0, "recordsFiltered": 0, "data": [ [ 1, "bitcoin", "Bitcoin", "3567.06", "59112700000", "0.23", 0, 0, 0, "https:\/\/www.reddit.com\/r\/Bitcoin\/", "326400", 923, "Bitcoin", "325888", 906 ] ] }

    That's working fine, but I get an alert error when I load the table:

    "DataTables warning: table id=data_index - Requested unknown parameter '7' for row 0, column 7"

    Do you have any idea what's wrong?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    As Allan said if your data value is 0 you aren't returning anything. You need to return a value otherwise its undefined and an error.

    Kevin

  • capcoincapcoin Posts: 6Questions: 2Answers: 0
    edited September 2017

    OK. I've tried with this JSON:

    {
      "draw": 1,
      "recordsTotal": 0,
      "recordsFiltered": 0,
      "data": [
        [
          1,
          "bitcoin",
          "Bitcoin",
          "3567.06",
          "59112700000",
          "0.23",
          "nolink",
          0,
          0,
          "https:\/\/www.reddit.com\/r\/Bitcoin\/",
          "326400",
          923,
          "Bitcoin",
          "325888",
          906
        ]
      ]
    }
    

    I've change 0 to "nolink"...and after....

    $(document).ready(function() {
      $('#data_index').DataTable({
        "ajax": 'data_index.php',
        "iDisplayLength": 100,
        "columnDefs": [{
          "render": function(data, type, row) {
            if (row[6] != "nolink" )
              return row[6];
          },
          "targets": [6]
        }]
      });
    });
    

    That's change anything. The values are correctly display (or not) but I get the same alert error when I load the table.

    Do you have any idea ?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    In your render function you are potentially not returning anything.

    You have this:

        "columnDefs": [{
          "render": function(data, type, row) {
            if (row[6] != "nolink" )
              return row[6];
          },
    

    But you should have this:

        "columnDefs": [{
          "render": function(data, type, row) {
            if (row[6] != "nolink" )
              return row[6];
           return data;   <<< add this to return something to the table
          },
    

    You can return the original data like I show above or something else. Your function needs to return something or you will get the unknown parameter error.

    Kevin

  • capcoincapcoin Posts: 6Questions: 2Answers: 0

    Thank's a lot, that's works perfectly :)

This discussion has been closed.