Giter Site home page Giter Site logo

Comments (8)

gauravmak avatar gauravmak commented on August 23, 2024 1

I will need to check this.

from laratables.

gauravmak avatar gauravmak commented on August 23, 2024

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.

ervansanjaya avatar ervansanjaya commented on August 23, 2024

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.

  1. Using the model of pivot table, it requires to have ID on the pivot table, while I didn't have one.

  2. 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 property extraAttributeColumnName 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.

gauravmak avatar gauravmak commented on August 23, 2024

You can treat quantity as a custom column.

Then, you can use laratablesQueryConditions() to load the relation.

from laratables.

ervansanjaya avatar ervansanjaya commented on August 23, 2024

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.

ervansanjaya avatar ervansanjaya commented on August 23, 2024

Thank you so much @gauravmak

from laratables.

ervansanjaya avatar ervansanjaya commented on August 23, 2024

@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.

gauravmak avatar gauravmak commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.