Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

How to add a onclick event to the row and get the row data #421

Open
anthonymanzo opened this issue Feb 15, 2018 · 1 comment
Open

How to add a onclick event to the row and get the row data #421

anthonymanzo opened this issue Feb 15, 2018 · 1 comment

Comments

@anthonymanzo
Copy link

Hi,
Awesome package!

What would the recommended way of adding an onclick event to the entire row (except the edit/delete buttons column)?

I want to have the grid rows be clickable and link to the Read component of a DataEdit page (?show=id) so I need to get access to the row data also.

I'm using laravel 5.x and the latest greatest rapyd-laravel package.

Here's my grid def:

    {
    	$q = \DB::table('drug_dispensations')
    	->leftJoin('drug_inventory','drug_inventory.id','=','drug_dispensations.drug_inventory_id')
    	->leftJoin('drug_orders','drug_orders.id','=','drug_inventory.drug_order_id')
        ->leftJoin('drug_products', 'drug_products.id', '=', 'drug_inventory.drug_product_id')
      	->leftJoin('drugs', 'drugs.id', '=', 'drug_products.drug_id')
      	->leftJoin('drug_types','drug_types.id','=','drugs.drug_type_id')
        ->leftJoin('drug_schedules','drug_schedules.id','=','drugs.drug_schedule_id')
        ->select(\DB::raw(
        	'drug_dispensations.*,
			drug_inventory.drug_label_id,
			drug_inventory.drug_expiration_date,
			drug_inventory.lot_number,
			drug_products.product_name,
			drugs.drug_name,
			drug_orders.order_date,
			drug_orders.order_received_date,
			drug_orders.id drug_order_id'
        	)
        );
        
        $filter = \DataFilter::source($q);
    	
    	$filter->add('product_name','Drug Product', 'text');
        
        $filter->add('drug_label_id','Label ID','text');
        
        $filter->add('dispense_date','Dispensed','daterange')->format('Y-m-d', 'en');
        
        $options = array(
        	''=>'All',
        	'Dispensed'=>'Dispensed',
        	'Spent'=>'Spent',
        	'Surrendered'=>'Surrendered'
        );
        
        $filter->add('disposition_type','Disposition','select')
		->options(
			$options	
		);
		
		$filter->submit('search');
        
        $filter->reset('reset');
       
       	$filter->build();

        $grid = \DataGrid::source($filter);
        
        $grid->attributes(array("class"=>"table table-striped"));
        
        $grid->add('product_name','Product', true);
    	
    	$grid->add('drug_label_id','Label ID',true);
    	
    	$grid->add('lot_number','Lot Number',true);
    	
    	$grid->add('dispense_date','Dispensed Date', true);
    		
    	$grid->add('disposition_type','Dispositon',true);
    	
    	$grid->add('disposition_date','Disposition Date', true);
    	
    	$grid->edit('/drugs/drug-dispensations/edit', 'Edit','modify|delete'); 
    	
    	$grid->orderBy('updated_at','desc'); //default orderby

		$grid->paginate(10); //pagination

		return view('drugs/drug-dispensations', compact('grid','filter'));
    
    }

and here's my blade:


@push('styles')
	{!! Rapyd::styles() !!} 
@endpush

@section('content')

<div class="row">
	<div class="col-md-12">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">Drug Dispensations</h3>
			</div>
			<div class="panel-body">
				{!! $filter !!}
				{!! $grid !!} 
			</div>
		</div>
	</div>
</div>

@endsection

@push('scripts')
 {!! Rapyd::scripts() !!}
@endpush
@dlaynes
Copy link

dlaynes commented Mar 11, 2018

I haven't worked with Rapyd in a while, but I'd use jQuery for this:

`
jQuery('.panel-body').on('click', 'tr', function(e){

//if e.target is not a button
//find a way to obtain the id based on the current row (perhaps it is hardcoded as a dom attribute)

});
`

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