'Cannot read property 'DT_RowId' of undefined

I am calling API of 1 Laravel project to another Laravel project.

I am getting an following error:

jquery.dataTables.min.js:22 Uncaught TypeError: Cannot read property 'DT_RowId' of undefined

I have tried to provide offset and limit by default 0 and 10

$limit = 10;
$start =0;

Following is my project code

Project 1

public function Jobe(Request $req)
{
    $columns = array(
        0 => 'jobid',
        1 => 'B',
        2 => 'C',
        3 => 'D',
        4 => 'E',
        5 => 'F',
        6 => 'G',
        7 => 'H',
        8 => 'I',
        9 => 'J'
    );

$limit = $req->input('length');
$start = $req->input('start');
$order = $columns[$req->input('order.0.column')];  
$sort['dir'] = $req->input('order.0.dir');
$job_pos_id = $req->get('Jobid');

$data = [
    'Job_pos_id' => $job_pos_id,    
    'start' =>$start,
    'length' =>$limit,
];

$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, 
     CURLOPT_URL,"http:/localhost/PQWE/public/api/Api");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 
    'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$server_output = curl_exec($ch);
$err = curl_error($ch);
curl_close ($ch);

$totalData=$server_output[0];
$totalFiltered=$server_output[1];
foreach ($server_output as $acc)
{
    $nData['jobid'] = $acc['job_pos_id'];
    $data[] = $nData;
}

$json_data = array(
    "draw"            => intval($req->input('draw')),  
    "recordsTotal"    => intval($totalData),  
    "recordsFiltered" => intval($totalFiltered), 
    "data"            => $data,
    "count"           => $totalData,
);

return response()->json($json_data);

Project 2

public function Api(Request $req)
{ 
    $limit = $req->input('length');
    $start = $req->input('start');
    $job_pos_id = $req->get('Jobid');

    if($job_pos_id == NULL) {
        $query = DB::connection('QWEERR')
        ->table('XYZ')->offset($start)->limit($limit)
        ->get()->toJson();

        $Totaldata= DB::connection('QWEERR')
        ->table('XYZ')->offset($start)->limit($limit)
        ->get();

    } else {
        $query = DB::connection('QWEERR')
        ->table('XYZ')->where('XYZ.jid','ILIKE', 
        '%'.$job_pos_id.'%')->get()->toJson();

        $Totaldata= DB::connection('QWEERR')
        ->table('XYZ')->where('XYZ.jid','ILIKE', 
       '%'.$job_pos_id.'%')->get();
    }

    $Total=count(Totaldata);
    Totalfiltered=$Total;
    return response()->json($query,Total,Totalfiltered);
}

Pagination error getting and at the time of search data not attaching error getting is:- Uncaught TypeError: Cannot read property 'DT_RowId' of undefined



Solution 1:[1]

I was getting a very similar message with the latest DataTables.Net:

TypeError: Cannot read properties of null (reading 'DT_RowId')

I realised the JSON data source I was using had some NULL items.

In my code I was easily able to fix it by not returning any null items (that get serialized to Json):

return lists.Where(item => item != null).ToList();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1