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

use pjax and service implement datatable #1486

Open
arbabi2010 opened this issue Oct 28, 2017 · 3 comments
Open

use pjax and service implement datatable #1486

arbabi2010 opened this issue Oct 28, 2017 · 3 comments

Comments

@arbabi2010
Copy link

Hi , I'm using service implement datatable with pjax page . when page refresh datatable show me correctly but when page change by pjax datatable doesn't work . how can i use pjax and service implement . my datatable is like this

{!! $dataTable->scripts() !!}
@yajra
Copy link
Owner

yajra commented Nov 8, 2017

Hmm, I think you need to overwrite the render method and exclude the pjax request.

    public function render($view, $data = [], $mergeData = [])
    {
        if ($this->request()->ajax() && $this->request()->wantsJson() && ! request()->pjax()) {
            return app()->call([$this, 'ajax']);
        }

        parent::render($view, $data = [], $mergeData = []);
    }

Just replace __PJAX__ with the logic on how you determine pjax request.

On the other hand, maybe we can exclude pjax by default. If ever you make it work, can you submit a PR? May not be able to check this atm. Thanks!

--EDIT--
I just found out that it's just request()->pjax() to determine pjax request.

@arbabi2010
Copy link
Author

I change my render like this

    public function render($view, $data = [], $mergeData = [])
    {
        if ($this->request()->ajax() && $this->request()->wantsJson() && request()->pjax()) {
            return app()->call([$this, 'ajax']);
        }

        if ($action = $this->request()->get('action') AND in_array($action, $this->actions)) {
            if ($action == 'print') {
                return app()->call([$this, 'printPreview']);
            }

            return app()->call([$this, $action]);
        }

        return view($view, $data, $mergeData)->with($this->dataTableVariable, $this->getHtmlBuilder());
    }

but no render table in view .

@arbabi2010
Copy link
Author

arbabi2010 commented Nov 9, 2017

I think , i need to Reinitializing datatable in pjax option but i don't now how cant i Reinitializing datatable ,
if i use datatable with jquery i can Reinitializing that like below but i don't khow how Reinitializing that with

{!! $dataTable->scripts() !!}

but data table jquery like below

    $(document).on('ready pjax:end', function(event) {
        $('#reportTable').dataTable();
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants