getting 'Requested unknown parameter' error when I trying to sorting

getting 'Requested unknown parameter' error when I trying to sorting

quick12quick12 Posts: 1Questions: 1Answers: 0
edited June 2022 in Free community support

I'm using Datatables.js with Laravel. I am getting data with serverside function of Datatables.js but when I try to sort on the 'price' column I get the following error.

Note: This discussion is my first. Sorry for code lines.

Requested unknown parameter 'null' for row 0, column 2.

Where am I missing?

<table id="ordersTable" class="table-striped table" >
     <thead>
        <tr>
            <td>
               <div class="iconFlex">
                  ORDER NUMBER
               </div>
            </td> 
            <td>STORE</td> 
            <td>STATUS DATE</td> 
            <td>PRODUCT</td>
            <td>BUYER</td>
            <td>Dimension/Weight</td>
            <td>PRICE</td>
            <td>STAT</td>
          </tr>
        </thead>
   </table>
$(function () {
    $("#ordersTable").DataTable({
      "ordering": true,
      columnDefs: [{
        orderable: false,
        targets: "no-sort"
      }],
      order: [[ 0, 'asc' ]],
      processing: true,
      serverSide: true,
      ajax: "{{route('index')}}",
      columns: [
    {
      data: 'price',
      render: function (data, type) 
      {
        if (type === 'display') 
        {
          return '£'+data;
        }
       }
    },
  ]
    });
  });

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

Answers

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769
    edited June 2022

    You have this:

        {
          data: 'price',
          render: function (data, type)
          {
            if (type === 'display')
            {
              return '£'+data;
            }
           }
        },
    

    The columns.render function always needs to return something. You aren't returning anything if the type is not display. This change should help.

        {
          data: 'price',
          render: function (data, type)
          {
            if (type === 'display')
            {
              return '£'+data;
            }
            return data;
           }
        },
    

    Kevin

Sign In or Register to comment.