Skip to content

Commit 4bfc4b4

Browse files
committed
Added setter and getter for getHtmlAttribute()
1 parent 4f5a238 commit 4bfc4b4

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/Datagrid.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function initDatagridOptions()
429429
*/
430430
public function getMethod()
431431
{
432-
return $this->datagridOptions['attr']['data-method'];
432+
return $this->getHtmlAttribute('data-method');
433433
}
434434

435435
/**
@@ -440,7 +440,7 @@ public function getMethod()
440440
*/
441441
public function setMethod($method)
442442
{
443-
$this->datagridOptions['attr']['data-method'] = $method;
443+
$this->setHtmlAttribute('data-method', $method);
444444

445445
return $this;
446446
}
@@ -452,7 +452,7 @@ public function setMethod($method)
452452
*/
453453
public function getUrl()
454454
{
455-
return $this->datagridOptions['attr']['data-url'];
455+
return $this->getHtmlAttribute('data-url');
456456
}
457457

458458
/**
@@ -463,11 +463,48 @@ public function getUrl()
463463
*/
464464
public function setUrl($url)
465465
{
466-
$this->datagridOptions['attr']['data-url'] = $url;
466+
$this->setHtmlAttribute('data-url', $url);
467467

468468
return $this;
469469
}
470470

471+
/**
472+
* Get single datagrid Html attribute.
473+
*
474+
* @param string $key
475+
* @param $default
476+
* @return mixed
477+
*/
478+
public function getHtmlAttribute($tag, $default = null)
479+
{
480+
return array_get($this->datagridOptions['attr'], $tag, $default);
481+
}
482+
483+
/**
484+
* Set single Html attribute on datagrid.
485+
*
486+
* @param string $option
487+
* @param mixed $value
488+
*
489+
* @return $this
490+
*/
491+
public function setHtmlAttribute($tag, $value)
492+
{
493+
$this->datagridOptions['attr'][$tag] = $value;
494+
495+
return $this;
496+
}
497+
498+
/**
499+
* Get all datagrid options.
500+
*
501+
* @return array
502+
*/
503+
public function getHtmlAttributes()
504+
{
505+
return $this->datagridOptions['attr'];
506+
}
507+
471508
/**
472509
* @return string|null
473510
*/
@@ -602,9 +639,10 @@ protected function render($options, $columns, $showStart, $showColumns, $showEnd
602639
->make($datagridView)
603640
->with(compact('showStart', 'showColumns', 'showEnd'))
604641
->with('datagridOptions', $datagridOptions)
605-
->with('tableAttrs', $this->datagridHelper->prepareAttributes($this->datagridOptions['attr']))
642+
->with('tableAttrs', $this->datagridHelper->prepareAttributes($this->getHtmlAttributes()))
606643
->with('columns', $columns)
607644
->with('exclude', $this->exclude)
645+
->with('data', $this->data)
608646
->render();
609647
}
610648

0 commit comments

Comments
 (0)