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

setValueCalculator in view-components/grids #43

Open
anp241 opened this issue Dec 2, 2017 · 1 comment
Open

setValueCalculator in view-components/grids #43

anp241 opened this issue Dec 2, 2017 · 1 comment

Comments

@anp241
Copy link

anp241 commented Dec 2, 2017

I have used the following code to return the value to the view-components/grids - setValueCalculator, but the below code is setting the same value in all rows of the grid - either the first row value of database table or the last value of database table.

public function getzonename()
    {
        $result=array();
        $zoneids = state_masters::all(['zone_id']);
        $array_length = count($zoneids);
        $iteration    = 0;
        $zonenames = array();
        $idval="";
        $count = 0;
                          
        while($iteration < $array_length)
        {
            $idval = $zoneids[$iteration];
            $zonenames[] = DB::select('select zone_name from zone_masters where id = ?',[$idval->zone_id]);
                                        
            $iteration++;
            
        }
    
          return $zonenames;
        
    }

--------------------------------------------------------------------------------------------------------

public function shownewgrid(Request $request)
    {
        $provider = new EloquentDataProvider(state_masters::class);
        
        
        
           $input = new InputSource($_GET);
           
        $columns = [
                        'Zone Name' => new Column('Zone Name'),
                        'state_name' => new Column('state_name'),
                        'id' => new Column('Update'),
                       'deleterec' => new Column('Delete record'),
                         new PageSizeSelectControl($input->option('page_size', 10), [2, 5, 10]),// allows to select page size
                         new PaginationControl($input->option('page', 1), 5), // 1 - default page, 5 -- page size
                         new CsvExport($input->option('csv'))
                        
                     ];
                    
              $grid = new Grid( $provider, $columns);
              
            
        
                $columns['Zone Name']->setValueCalculator(function($row)
                {
                     $row = StateController::getzonename();
                        
                     for ($i=0;$i<sizeof($row);$i++) 
                     {
                        
                        return $row[$i][0]->zone_name;
                                     } 
                    
                });
          
          
            $columns['id']->setValueFormatter(function ($id, $row) 
            {
            return "<a href='". url('/editstaterecord')."/{$row->id}'>Update</a>";  
            })
            ->getDataCell()
            ->setAttribute('onclick', 'window.location = $(this).find(\'a\').attr(\'href\'));')
            ->setAttribute('style', 'cursor:pointer');
            
           $columns['deleterec']->setValueFormatter(function ($id, $row) 
           {
             return "<a href='". url('/deletestaterecord')."/{$row->id}'>Delete</a>";
           })
           ->getDataCell()
        
           ->setAttribute('onclick', 'return confirm("Are you sure you want to delete this item?");')
           ->setAttribute('style', 'cursor:pointer');
           
         
            //  but also you can add some styling:
            $customization = new BootstrapStyling();
            $customization->apply($grid);
            
            $items = zone_masters::all(['id', 'zone_name']);
         
              return view('masters.state', compact('grid','items'));
    }

How do I update the code

@wdog
Copy link

wdog commented Mar 21, 2018

your code always return the first record

return $row[$i][0]->zone_name;

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

2 participants