Skip to content

Question : Set Total Records, Skip Total Records, setFiltered records does it also work with DB? #2326

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

Closed
benyaminl opened this issue Feb 21, 2020 · 2 comments

Comments

@benyaminl
Copy link

benyaminl commented Feb 21, 2020

Reffered to #578 and #779

Summary of problem or feature request

I use skipTotalRecords(), setTotalRecords(0), and setFilteredRecords(0) but the datatables class still query agregate to get the result count. Is there I'm missing here?
image

But when I dd the datatables object
image
The skipTotalRecords are true and I think it should return the set record or even not doing anything at all on
https://github.com/yajra/laravel-datatables/blob/9.0/src/QueryDataTable.php#L158-L167
and https://github.com/yajra/laravel-datatables/blob/9.0/src/QueryDataTable.php#L158-L167
But seems it's not working instead still query the agregate that cause slow process of datatables.

Code snippet of problem

// @see https://yajrabox.com/docs/laravel-datatables/master/engine-query
        $db = DB::table("mhcustomer", "c")
                ->select(["c.nomor", "kode_hokky", "nama", "telepon_hp", "s.point", "s.point_tier"])
                ->join(DB::raw("(select `s`.`nomormhcustomer`,
                    sum(s.jumlah) as point,
                    sum(s.jumlah_tier) as point_tier
                from
                    tsaldo_membership s
                group by s.nomormhcustomer) as `s`"), "s.nomormhcustomer", "=", "c.nomor");
                
        return DataTables::of($db)        
                ->skipTotalRecords()
                ->setTotalRecords(0)
                ->setFilteredRecords(0)
                // see @https://datatables.yajrabox.com/eloquent/post-column-search
                // see @https://datatables.yajrabox.com/fluent/custom-filter untuk cata SULIT
                // terpaksa kalau kolomnya agregate kaya sum, count, iffnul, dll, tapi kalau ga, pakai get cukup
                // @see https://datatables.yajrabox.com/relation/has-one
                // Itu untuk Kasus Pakai Relationship nambah kolom, jadi ga perlu raw query
                ->setTransformer(function($item){

                    return [
                        'nomor'         => $item->nomor,
                        'kode_hokky'    => $item->kode_hokky,
                        'nama'          => $item->nama,
                        'telepon_hp'    => $item->telepon_hp,
                        'point'         => $item->point,
                        'point_tier'    => $item->point_tier,
                        'tier'          => ''
                    ];
                })
                ->make(true);

System details

  • Operating System : Windows 10 1909
  • PHP Version : php 7.4
  • Laravel Version : 6.x
  • Laravel-Datatables Version : 1.5.0 (9.8.0)
@benyaminl
Copy link
Author

Seems the answer is the param of the skipTotalRecords should be bigger than 0 and the setFilteredRecords also should be bigger than zero.

@dhcmega
Copy link

dhcmega commented Jun 19, 2022

@benyaminl hi! have you figured this out? I'm having the same problem. Thanks!

skipTotalRecords doesn't take any params

    /**
     * Skip total records and set the recordsTotal equals to recordsFiltered.
     * This will improve the performance by skipping the total count query.
     *
     * @return $this
     */
    public function skipTotalRecords()
    {
        $this->skipTotalRecords = true;

        return $this;
    }

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants