Child Rows
Child Rows
mcaleer
Posts: 11Questions: 2Answers: 0
Hey everyone, I am trying to add the "child rows" to my current datatable. I tried to follow the example shown here: https://datatables.net/examples/api/row_details.html but it seems as though it breaks my table. Looking for someone to give me a pointer on how to get it working. The table i am trying to add it to can be found here: http://www.nythermal.com/index.php?page=parts-list . Appreciate the help !
This discussion has been closed.
Answers
Bump -- Could really use some help here... Doesn't sound too difficult but clearly i am doing something wrong.
Hi,
Thanks for the link. I've just tried it and the child rows in your table appear to work okay for me (Chrome / Mac).
There are a number of errors on the page, including 404 and Javascript errors, which might has some impact and I would suggest resolving them, but I'm afraid I don't see the issue immediately.
Allan
It works but it doesn't work. Is there a way to do the same thing without using Ajax?
I am pulling data from a Module inside of CMS Made Simple.. This is my current code:
The "return function" for the child rows will not properly pull the data from my source. For example: {$entry->price} is pulling the price for one product and is applying it to every product in the table.. Each product has their own price so im not sure why it is only grabbing one price and using it for everything.
You can see here: http://www.nythermal.com/index.php?page=parts-list that everything has a price of 545.4 which is incorrect.
But yet, when you view the page source, it appears that all the correct prices are found.
Any Ideas?
Sounds like your code is generating a static function for the row details. I would suggest using a function that uses the Javascript object
d
rather than the template value of{$entry->price}
.Allan
Allan, I really appreciate the prompt reply's. I am definitely no expert when it comes to datatables. Do you mind explaining your last comment with a bit more detail or a quick sample of what you mean?
In this example - take a look at line 7 in the Javascript code block below the table - it uses the data from the row passed in.
Creating a function for each row isn't going to work, since only the last row will "win" (you would just be overwriting exisiting functions called
format
if you did that).Allan
Please excuse my little knowledge as I am trying my best to understand.
Line 7 shows:
( This is pulling the name from Ajax is it not? )
If i am not using Ajax I don't quite understand how to make the function work.
How would i then use the {$entry->price} ?
I feel like this should be rather simple but I seem to be overlooking the solution.
Bump - Ill buy beer for who ever can help me get this working lol
You wouldn't since it doesn't exist in that context.
What I would suggest you do is something like this in your r ow template:
i.e. as well as your existing visible data in the columns, add
data-*
attributes to contain the data that you don't want the users to be able to see directly in the table columns.Then, modify the call to
format()
to simply be:so you are passing in the row object.
Now you can use:
to access the price or any of the other data points added.
Allan
Allan,
In your example above what made you pick data-name="{$entry-name}",
{$entry-name} is in fact a variable within my data so i feel as though it will grab that data and confuse it? Can the name be anything? Such as data-name="cost".
So then in my code above line 50 would =
and then row 61 would =
After that you say to use
With reference to my above code where would that be placed?