Comments (8)
I will need to check this.
from laratables.
I haven't put pivot table data in Datatables before.
Are you trying to get the pivot data directly? i.e. Using the model of the pivot table to prepare the datatables data? Or fetching the many to many relationship from a model?
from laratables.
I haven't put pivot table data in Datatables before.
Are you trying to get the pivot data directly? i.e. Using the model of the pivot table to prepare the datatables data? Or fetching the many to many relationship from a model?
Thank you for your response @gauravmak
I tried both of it.
-
Using the model of pivot table, it requires to have ID on the pivot table, while I didn't have one.
-
Using the many to many relationship, I'm having issue on accessing my extra attribute in my pivot table, i tried
using()
+withPivot('extraAttributeColumnName')
but it said propertyextraAttributeColumnName
doesn't exist.
My example data is I have two many-to-many table items
and users
and it has item_user
that contains quantity
, and two referencing foreign key to items
and users
.
I want to be able to display in my datatable as such:
User Name | Item Name | Quantity
from laratables.
You can treat quantity as a custom column.
Then, you can use laratablesQueryConditions() to load the relation.
from laratables.
You can treat quantity as a custom column.
Then, you can use laratablesQueryConditions() to load the relation.
But how about the issue I have which is the query keep selecting ID of my pivot table when it actually didn't have one?
I only
columns: [
{ title: 'Use Name', name: 'user.name' },
]
But it keeps selecting 'id' of item_user
table.
from laratables.
Thank you so much @gauravmak
from laratables.
@gauravmak I ended up 'faking' my $primaryKey attribute on my pivot model to finally able to show my desired output. So I just named my pivot table's primary key with one column name of the referencing key, and voila, it's all solved.
But I'm hoping that this will be fixed soon (if it's actually a bug).
Thank you.
from laratables.
Ervan,
My example data is I have two many-to-many table items and users and it has item_user that contains quantity, and two referencing foreign key to items and users.
I want to be able to display in my datatable as such:
User Name | Item Name | Quantity
I didn't get how you want to display the data here. A user can have multiple items. You need to customize the value to maybe display them comma-separated or something. Example -
/**
* Returns comma-separated name for the datatables.
*
* @return string
*/
public function laratablesItemsName()
{
return $this->items->pluck('name')->implode(', ');
}
I just tried that and it worked for me. Reply if you're still facing any issues.
from laratables.
Related Issues (20)
- Non-static method App\Model\MyModel:laratablesRowData() HOT 1
- Undefined method HOT 4
- Is there a way to use custom data (fetched by another http api call from eg. stripe) in backend as the table data? HOT 1
- Getting ErrorException on passing parameter to custom controller via AJAX HOT 1
- Error Order Relational Column HOT 1
- Passe Custom Data Seach HOT 17
- How do I make the one to one polymorphic relationship searchable? HOT 2
- pagination not work when use group by HOT 1
- Ordering on custom field HOT 1
- Is the ID column hard-coded? HOT 3
- integration violation 'id' laratablesQueryConditions HOT 1
- One to One relationship Data returns N/A HOT 3
- Method laratablesQueryConditions field returning ambiguous mysql error on join columns HOT 1
- buttons with javascript prevent default not working HOT 2
- Laratable Class accepting parameters HOT 6
- Many2One Relation HOT 1
- No way to whitelist columns server-side HOT 2
- Add group by feature HOT 6
- does this support complex multiple row headers? HOT 1
- Incompatible with PHP 8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laratables.