I've been struggling with this for a few days.
I have an associative array, which I want to loop in my view. It works great when looping to create a table, for example.
The thing is, in another view, I am going to need to include some HTML (a button) in the array, that I am going to pass to the view as a JSON. I've tried it like this and it, no success.
$datacol[] = array(
'button' => '<a href="tasks/details/{{ $task->id }}" class="btn btn-sm">
<i class="bookmark big icon" data-toggle="tooltip" data-placement="top" title="Task Details"></i></a>',
'id' => $task->id,
'task_type' => (DB::table('tasktypes')->where('id','=', $task->task_type_id)->value('task_type')),
'related_block' => (DB::table('chapters')->where('id','=', $task->related_block)->value('description')),
'assigned_to' => (DB::table('users')->where('id','=', $task->assigned_to)->value('display_name')),
'time' => (DB::table('task_interactions')->where('task_id','=', $task->id)->pluck('task_time')->sum()),
'start_date' => (DB::table('task_interactions')->where('task_id','=', $task->id)->where('status','=','In Progress')->pluck('created_at')->first()),
'end_date' => (DB::table('task_interactions')->where('task_id','=', $task->id)->where('status','=','Finished')->pluck('created_at')->first()),
'status' => (DB::table('tasks')->where('id','=', $task->id)->value('status')),
'comments' => (DB::table('tasks')->where('id','=', $task->id)->value('comments'))
);
Does anyone knows a way of passing HTML inside the array and make sure that the array is rendered in the view.
<tbody>
#foreach($datacol as $d)
<tr>
<td>{{ $d['button'] }}</td>
<td>{{ $d['id'] }}</td>
<td>{{ $d['task_type'] }} - {{ $d['related_block'] }}</td>
<td>{{ $d['assigned_to'] }}</td>
<td>{{ $d['time'] }}</td>
<td>{{ $d['start_date'] }}</td>
<td>{{ $d['end_date'] }}</td>
<td>{{ $d['status'] }}</td>
<td>{{ $d['comments'] }}</td>
</tr>
#endforeach
</tbody>
Thanks in advance
Change your array like this you need to give proper html string for button since it will not further parsed by blade. In href you are using blade ({{}}) to append $task->id, That's why it will not append proper id to the url. you need to use (.) to concatenate id to url.
$datacol[] = array(
'button' => '<a href="tasks/details/'.$task->id.'" class="btn btn-sm">
<i class="bookmark big icon" data-toggle="tooltip" data-placement="top" title="Task Details"></i></a>',
'id' => $task->id,
// other stuff
);
And then in view render button using {!! $html !!}
<tbody>
#foreach($datacol as $d)
<tr>
<td>{!!$d['button'] !!}</td>
<td>{{ $d['id'] }}</td>
<td>{{ $d['task_type'] }} - {{ $d['related_block'] }}</td>
<td>{{ $d['assigned_to'] }}</td>
<td>{{ $d['time'] }}</td>
<td>{{ $d['start_date'] }}</td>
<td>{{ $d['end_date'] }}</td>
<td>{{ $d['status'] }}</td>
<td>{{ $d['comments'] }}</td>
</tr>
#endforeach
</tbody>
I hope it will help :)
Remove the button key-value pair completely from the PHP code and render the markup in the view.
You can generate the <a> tag in the view, only using the id you passed ({{ $id }}):
<a href="tasks/details/{{ $id }}" class="btn btn-sm">
<i class="bookmark big icon" data-toggle="tooltip" data-placement="top" title="Task Details"></i></a>
No need to mix HTML in your PHP code (considering you're using Laravel, which completely isolates the view from other code).
Related
currently I am scraping some website and return the value of the scraped data (from json file) into an HTML table in one of the component file in vue.js When displaying one of the value, I want this value to be put as href="link". However, since I am iterating all the data, "the link" is in the form of {{ row[8] }} which cannot be read by the vue code. I tried:
<a v-bind:href="{{ row[8] }}"> View </a>
<a href={{ row[8] }}> View </a>
View
but none of these work. Here is my code:
<tbody>
<tr v-for="row in sesami">
<td>{{ row[0] }}</td>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
<td>{{ row[4] }}</td>
<td>{{ row[5] }}</td>
<td>{{ row[6] }}</td>
<td>{{ row[7] }}</td>
<td>
View
</td>
</tr>
</tbody>
currently, with the code that I used, the hyperlink is mapped to the word "View" which is correct, but the value or the link is not inserted inside which caused the link when clicked to refresh the page instead. Please help....
Thank you
You do not need string interpolation when using the v-bind syntax as the scope of the expected argument is a javascript variable, e.g. row. Observe:
<a v-bind:href="row[8]"> View </a>
Which is syntactically the same as:
<a :href="row[8]"> View </a>
You could iterate through the row items and you reach the index 8 bind the item to the href attribute :
<tbody>
<tr v-for="row in sesami">
<td v-for="(item ,i) in row">
<template v-if="i===8">
<a v-bind:href="item" target="_blank"> View </a>
</template>
<template v-else>
{{item}}
</template>
</td>
</tr>
</tbody>
I want to fetch the data from a table which is in database and then display it in tabular format in my webpage. Only the html column name is being shown but not the data from the database table. Can anyone please help me out with this?
My codes:
views.py:
def display_majorheads(request):
outputs = ProcessedOutputs.objects.all()
be_year = 0
context = {
'processed_outputs':outputs,
'be_year':be_year,
}
return render(request, 'website/mhead.html', context )
mhead.html:
<table class="table table-striped">
<tr>
<th>MajorHead</th>
<th>BeSalary</th>
<th>BeGiaSalary</th>
<th>BeOther</th>
<th>BeTotal</th>
<th>BeNextyrSalary</th>
<th>BeNextyrGiaSalary</th>
<th>BeNextyrOthrs</th>
<th>BeNextyrTotal</th>
</tr>
{% for processed_outputs in outputs %}
<tr>
<td>{{ processed_outputs.major_cd }}</td>
<td>{{ processed_outputs.be_salary }}</td>
<td>{{ processed_outputs.be_gia_salary }}</td>
<td>{{ processed_outputs.be_other }}</td>
<td>{{ processed_outputs.be_total }}</td>
<td>{{ processed_outputs.be_nextyr_salary }}</td>
<td>{{ processed_outputs.be_nextyr_gia_salary }}</td>
<td>{{ processed_outputs.be_nextyr_others }}</td>
<td>{{ processed_outputs.be_nextyr_total }}</td>
</tr>
{% endfor %}
</table>
almost there!
{% for processed_outputs in outputs %}
has to be:
{% for outputs in processed_outputs %}
{{ outputs.major_cd }}
...
...
I want do report with HTML and put one column as title and supress repetition. I'm using Laravel 5.8.
This is my view code.
<div class="container">
<div class="table-responsive">
<div class="table table-striped table-bordered">
<table>
<thead>
<tr>
<th>Leito</th>
<th>Nº Atendimento</th>
<th>Dt. Atendimento</th>
<th>Paciente</th>
<th>Idade</th>
<th>CID Principal</th>
<th>CID</th>
<th>Médico</th>
<th>Dias internado</th>
<th>Observação</th>
</tr>
</thead>
<tbody>
#foreach($analytic as $patient)
<tr><td colspan="11"><strong>Setor: </strong>{{ $patient->setor }}</td></tr>
<tr class="{{ $patient->corlinha }}">
<td>{{ $patient->leito }}</td>
<td>{{ $patient->atendimento }}</td>
<td>{{ $patient->dtatendimento }}</td>
<td>{{ $patient->paciente }}</td>
<td>{{ $patient->idade }}</td>
<td>{{ $patient->cidp }}</td>
<td>{{ $patient->cid }}</td>
<td>{{ $patient->medico }}</td>
<td>{{ $patient->dias }}</td>
<td>{{ $patient->observacao }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
And this is my result:
Result
When "Setor" is same i need agroup them.
I need something like this:
Result that i need
Thank´s
In your case you need to groupBy your collection. I am giving an example.
Controller Code:
public function index()
{
$$analytic = Model::all()->groupBy('setor');
return view('view', compact('analytic '));
}
In blade your table will look like something:
<table>
#foreach ($analytic as $key => $data)
<tr>
<th colspan="10">{{ $key }}</th>
</tr>
#foreach ($data as $patient)
<tr>
<td>{{ $patient->leito }}</td>
<td>{{ $patient->atendimento }}</td>
<td>{{ $patient->dtatendimento }}</td>
<td>{{ $patient->paciente }}</td>
...........
...........
</tr>
#endforeach
#endforeach
</table>
Hope you can now work around to get your desired result. Read Laravel documentation about collection groupBy here.
I have a firestorm collection with this structure:
USERID {
email: "test#test.com"
name: "John Doe"
roles{
user: true
editor: true
admin: false
}
}
I am able to get this data as a collection and render it in the view.
component.ts:
constructor(private afs: AngularFirestore) {}
this.userCollection = this.afs.collection('users')
this.users = this.userCollection.valueChanges()
component.html
<tr *ngFor="let user of users | async;>
<td>{{ user.firstName }}</td>
<td>{{ user.lastName }}</td>
<td>{{ user.roles }}</td>
<td>{{ user.email }}</td>
<td>{{ user.job }}</td>
</tr>
Everything displays correctly except "roles" which displays as [object Object]
I can get roles to display by changing the line to
{{ user.roles | json }}
but that only displays the raw json data. How can I display the roles that are set to true? Is there a better way to structure my data?
role is object too. i you can get the property like this
<tr *ngFor="let user of users | async;>
<td>{{ user.firstName }}</td>
<td>{{ user.lastName }}</td>
<td>{{ user.roles.user }}</td>
<td>{{ user.email }}</td>
<td>{{ user.job }}</td></tr>
I am fairly new to Angular JS . I have a table like this .
<tr ng-repeat="job in jobs">
<td>{{ job.id }}</td>
<td>{{ job.companyName }}</td>
<td>{{ job.jobRole }}</td>
<td>{{ job.salary }}</td>
<td>{{ job.location }}</td>
<td>{{ job.jobTitle }}</td>
<td>{{ job.industry }}</td>
<td>{{ job.role }}</td>
<td>{{ job.aboutCompany }}</td>
<td>{{ job.natureOfWork }}</td>
<td>{{ job.idealCandidateProfile }}</td>
</tr>
and I am trying to fill it up using this .
function jobController($scope,$http) {
var url="http://52.74.160.253:8080/jobs/";
var LocalData = "data.txt";
$http.get(LocalData).success( function(response) {
$scope.jobs = response;
});
}
Now here is the weird part . I have the JSON data stored both locally and on the server , When i use the locally stored JSON data , it works fine . But when I use the url , I get displayed with an empty table .Both the local and url data are exactly the same .