Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatable return same values in different pages #29

Open
starking8b opened this issue Jun 15, 2022 · 0 comments
Open

Datatable return same values in different pages #29

starking8b opened this issue Jun 15, 2022 · 0 comments

Comments

@starking8b
Copy link

I am working on a project using Laravel with Mongo DB , this is my transformer

<?php


namespace App\Datatables;

use League\Fractal;
use App\Models\Device;
use Carbon\Carbon;
class DeviceTransformer extends Fractal\TransformerAbstract
{
public function transform(Device $device)
{
    $online='<a ><span class="avatar">  <span class="avatar-status-offline"></span>    </span>offline</a>';
        $vlan= $device->InternetGatewayDevice['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['X_HW_VLAN']['_value']??"";
        $mac=$device->VirtualParameters['Macaddress']['_value']??"";
        $pppoeUsername=$device->VirtualParameters['pppoeUsername']['_value']??"";
        $rxpower=$device->VirtualParameters['RXPower']['_value']??"";
        $ssid=$device->InternetGatewayDevice['LANDevice']['1']['WLANConfiguration']['1']['SSID']['_value']??"";
        $lastinform=$device->_lastInform ??"";
        $lastinform=Carbon::parse($lastinform)->format('Y-m-d H:i:s');

        $now=Carbon::now()->subMinutes(5);
        $last24hours=Carbon::now()->subHours(24);
          if($lastinform> $now)
              $online='<a><span class="avatar"> <span class="avatar-status-online"></span>   </span>Online</a>';
          elseif($lastinform<$now && $lastinform > $last24hours)
              $online='<a><span class="avatar"> <span class="avatar-status-busy"></span>  </span>Past 24 Hours</a>';


return [
'id'   => $device->_id,
'serial'=>$device->_deviceId['_SerialNumber'],
'productclass'=>$device->_deviceId['_ProductClass'],
'vendor'=>$device->_deviceId['_Manufacturer'],
'lastInform'=> $lastinform,
'vlan' => $vlan."",
'Mac'=>$mac,
'PPPusername'=>$pppoeUsername,
'RX'=>$rxpower,
'ssid'=>$ssid,
'action'=> "<a href='".$device->_id."'>Show</a>",
'online'=>$online
];
}

}

this is how I call data in the controller

$data=Device::query();


 return DataTables::of($data)
      ->setTransformer('App\Datatables\DeviceTransformer')

      ->make(true);

the problem is after 3 or 4 pages same raws comming to data table , and just 2 or 3 raws change.
how is that Possible, it seems datatable return same raws again and again in different pages .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant