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

Sorting edited columns #3

Closed
bart opened this issue Feb 19, 2015 · 1 comment
Closed

Sorting edited columns #3

bart opened this issue Feb 19, 2015 · 1 comment

Comments

@bart
Copy link

bart commented Feb 19, 2015

Sorry @yajra, but I have another question concerning sorting.
I selected some Ids for a hand full of columns which I edited afterwards.

Here is an example:

$projects = Project::select([
    'id',
    'username',
    'identity',
]);

return Datatables::of($projects)
    ->editColumn('identity', function($projects) {
        // Some magic number adaption
        $newValue = $this->getIdent($projects->identity);
        return $newValue
    })->make();

The problem on this is approach is that sorting the datatables uses the selected values from the $projects object and doesn't take edited columns into account, right?

So if I have 3 entries where the identity field in the database are 10, 20 and 30. After some magic number adaption they will be presented as 901, 800, 1904. So when I sort the results, I get the wrong order, right? Any solution for that?

Thanks and kind regards!

@yajra
Copy link
Owner

yajra commented Feb 19, 2015

Since sorting is done on the database level, you would have to put the logic on getting identity field on the database side. You can either create a database view or function to get the identity for sorting to work for your case.

On the other hand, I mostly disable the specific field sorting function whenever I encounter this case since it's computed.

Regards!

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