Laravel-admin: Trying to get serial no in Grid

Created on 17 Aug 2019  ·  5Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.8
  • PHP Version: 7.2
  • Laravel-admin: 1.6

Description:

I am trying to add a serial to the grid but failed.

Steps To Reproduce:

        protected function grid()
        {
            $grid = new Grid(new TransactionLedger);

            $grid->rows(function ($row){
                $this->serial = $sl = $row->model()['id'];
                if($row->model()['id']%4==3){
                    $row->style("background-color:#eee");
                }
                if($row->model()['id']%4==0){
                    $row->style("background-color:#eee");
                }
            });
            $grid->column('SL')->display(function(){
                 return $this->serial ;
            });
        }

Most helpful comment

All 5 comments

It seems that you want to display id field to SL column, why no just use $grid->column('id', 'SL');

@z-song Sorry, $grid->column('id', 'SL'); it's returning the id , but i need the serial number not id. I want to show the serials like :
1
2
3
4

This works, but problems in pagination. When going to the next page it starts from 1 again.

It's working for single page, when I am using pagination it's counting from 1 in the second page.
Could you please give me a suggestion to solve this issue.

Was this page helpful?
0 / 5 - 0 ratings