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

How to display user defined column name in yajra datatables #2458

Closed
Nahiyan47 opened this issue Sep 5, 2020 · 7 comments
Closed

How to display user defined column name in yajra datatables #2458

Nahiyan47 opened this issue Sep 5, 2020 · 7 comments
Labels

Comments

@Nahiyan47
Copy link

Nahiyan47 commented Sep 5, 2020

i am trying to view datatables where i have user defined columns. It is showing the name of table column automatically.

i have a class IncomesourceDatatable and from that class i am rendering to my view
below i have a function getColumns.

protected function getColumns()
{
return [
'title',
'description',
'special_rule',
'amount',
'created_at',
];
}

as i can see it shows the table column name as the column name in view, how can i put a user defined column name for example title as My Ttile

@gebaiwan
Copy link

addColumn?

@Nahiyan47
Copy link
Author

can you please elaborate .?

@gebaiwan
Copy link

->addColumn('rename_title', function($datum){ return $datum->title }) ->filterColumn('rename_title', function($query, $keyword) { $sql = "select title like ?"; $query->whereRaw($sql, ["%{$keyword}%"]); })

js script: {data:'rename_title', name:'rename_title'}

will this solve your problem?

@shabeebrizvi
Copy link

->addColumn('rename_title', function($datum){ return $datum->title }) ->filterColumn('rename_title', function($query, $keyword) { $sql = "select title like ?"; $query->whereRaw($sql, ["%{$keyword}%"]); })

js script: {data:'rename_title', name:'rename_title'}

will this solve your problem?

->title('UserDefined')

@demetreeus
Copy link

I assume the attributes here are compatible https://yajrabox.com/docs/laravel-datatables/master/html-builder-column .
So,

return [
 ['name' => 'column_1', 'title' => 'Da Column', 'data' => 'column_1'],
 ['name' => 'column_2', 'title' => 'Another Column', 'data' => 'column_2'],
]

works for me.

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Dec 26, 2022
@github-actions
Copy link

github-actions bot commented Jan 2, 2023

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

@github-actions github-actions bot closed this as completed Jan 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants