laravel-datatables-html icon indicating copy to clipboard operation
laravel-datatables-html copied to clipboard

Sorted Columns

Open enextiarg opened this issue 6 years ago • 5 comments

Summary of problem or feature request

Needed sorted columns

Code snippet of problem

private function compileTableHeaders()
    {
        $th = [];
        foreach ($this->collection->toArray() as $row) {
            $thAttr = $this->html->attributes(array_merge(
                array_only($row, ['class', 'id', 'width', 'style', 'data-class', 'data-hide']),
                $row['attributes']
            ));
            $th[] = '<th ' . $thAttr . '>' . $row['title'] . '</th>';
        }

        return $th;
    }

System details

We could add a sortBy in the foreach in line 587 of Builder file

private function compileTableHeaders()
    {
        $th = [];
        foreach ($this->collection->sortBy('order')->toArray() as $row) {
            $thAttr = $this->html->attributes(array_merge(
                array_only($row, ['class', 'id', 'width', 'style', 'data-class', 'data-hide']),
                $row['attributes']
            ));
            $th[] = '<th ' . $thAttr . '>' . $row['title'] . '</th>';
        }

        return $th;
    }

enextiarg avatar Jul 02 '19 11:07 enextiarg

Sorry for late reply. Please do not hesitate to submit a PR if you still need. Thanks!

yajra avatar May 07 '22 16:05 yajra

Hi, it's only a proposal, it could be interesting sort columns before render.

enextiarg avatar May 07 '22 23:05 enextiarg

Sort before render, I think you just need orders option?

->orders([[1, 'desc'], [2, 'asc']])
->orderBy(3, 'desc')

For column arrangement, just set it in the getColumns() method?

yajra avatar May 08 '22 04:05 yajra

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 09 '22 03:10 github-actions[bot]

It's a proposal about columns order, not rows or data.

enextiarg avatar Oct 11 '22 18:10 enextiarg

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Nov 12 '22 03:11 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Nov 20 '22 03:11 github-actions[bot]