GSP Pagination and Checkboxes - pagination

I am wondering if it is possible to have checkbox states transfer over to the next page on a GSP, I am new to web development so I was wondering if anyone could provide me with any advice.
Currently, this is how I am utilizing my checkboxes:
<table>
<thead>
<tr></tr>
</thead>
<tbody>
<g:each in="${itemList}" status="i" var="instance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>
<g:checkBox name="selected"value="${instance.id}" checked="false" />
</td>
</tr>
</g:each>
</tbody>
And this is the pagination I am utilizing:
<div class="pagination">
<g:paginate total="${total}" params="${params}"/>
</div>
My issue is that the checkboxes do not persist while traversing the pages - is there a simple way I could solve this?

Related

Click element(selector by child text)

i need click checkbox on page with table:
<table>
....sample item...
<tr>
<td align="middle"><input type="checkbox" class="enableMacacl" checked=""></td>
<td>04:18:D6:3E:B4:79</td>
</tr>
</table>
but i need click this checkbox with selector by text "04:18:D6:3E:B4:79". How can i do this?
You need to wrap it inside <label for="checkboxId"></label> and then give id="checkboxId" to checkbox.
<table>
....sample item...
<tr>
<td align="middle"><input type="checkbox" id="checkbox" class="enableMacacl" checked=""></td>
<td><label for="checkbox">04:18:D6:3E:B4:79</label></td>
</tr>
</table>

Excel VBA getElementsByTagName

i'm trying to get a complex (ugly) nested table with no id but with a class name = "tableselect" then read all tr's and td's
the only quick and unique way to find the table - it is within a div tag, then a center tag.
this is the html structure.
<div align="center">
<center>
<table border='1' width='100%' cellspacing='0' cellpadding='5' class="tableselect">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
...
</table>
</center>
</div>
the .getElementsByTagName("center").getElementsByTagName("table") does not work
also
.getElementsByClassName("tableselect").getElementsByTagName("tr") does not work
using excel 2016

Laravel 5 - Download Excel file of a View

I'm working on adding an export/downloading feature to a Laravel 5 application. I found the Laravel-Excel library (http://www.maatwebsite.nl/laravel-excel/docs), which seems perfect -- ideally, I will be able to take a Laravel View or html and make a downloadable Excel file.
So far, I've gotten the creation and storage to work. I can create an Excel file, and it's okay (it's the right data and View), and on the server in storage/exports/ I see "Report.xls" - which is right save path. The issue I'm having is I cannot seem to download the file through the browser after creating it.
The Laravel-Excel library has ->download('xls') and ->export('xls') methods, but these only seems to return the raw content, which is visible in the developer's console:
On the right, you can see the file was created and stored as "Report.xls", and presumably the raw content is the right content - but I don't know why it's just spitting raw content into the console. I can open the Report.xls file in Excel, so I know it's not corrupted.
I also tried to use the Laravel 5 Response::download() function and set headers for the download, but it also spit out raw content in the console instead of downloading the file:
The code I'm using is an AJAX call that hits a Controller method, and the controller method just triggers a Service method called "downloadReportFile()":
public function downloadReportFile($requestData, $fileType) {
$configJSON = \Report::loadConfigFile($requestData['reportName']);
$today = Carbon::today()->format('Y-m-d');
$FileViewdata = array(
'config' => $configJSON,
'html' => $requestData['report_html']
);
\Excel::create("Report", function($excel) use ($FileViewdata) {
$excel->setTitle($FileViewdata['config']['title']);
$excel->setDescription($FileViewdata['config']['description']);
$excel->sheet("page 1", function($sheet) {
$sheet->loadView("reports.sample");
});
})->store('xls', storage_path('exports')); // ->export('xls');
$report_excelFilepath = storage_path('exports') . "/Report.xls";
return response()->download($report_excelFilepath, "Report.xls", [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => "attachment; filename='Report.xls'"
]);
}
The View being made into the Excel file is a simple table - the same table as in the screenshots. Here's the template/HTML of the View:
<div class="container full-width-container">
<link href="http://192.168.33.10/css/reports.css" rel="stylesheet">
<div id="results" class="row">
<div class="col-xs-12">
<h2 class="report-title">Active Products </h2>
<br>
<div class="row">
<div class="col-xs-12">
<div class="table-responsive report-component" name="table" template="table">
<table id="report-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="report-table-th">ENGINE</td>
<td class="report-table-th">PRODUCT COUNT</td>
<td class="report-table-th">PRODUCT PRICE</td>
</tr>
</thead>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meows</p>
</td>
<td class="report-table-cell">
<p>1,234</p>
</td>
<td class="report-table-cell">
<p>781230.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Paws</p>
</td>
<td class="report-table-cell">
<p>10,777</p>
</td>
<td class="report-table-cell">
<p>3919823.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meow Mobile</p>
</td>
<td class="report-table-cell">
<p>177</p>
</td>
<td class="report-table-cell">
<p>334323.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Tails Cloud</p>
</td>
<td class="report-table-cell">
<p>335</p>
</td>
<td class="report-table-cell">
<p>378918923.00</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Does anyone see what I might be missing to download an XLS file?
Thanks for your time!
EDIT
After doing some more research, it seems that my original workflow for downloading -- using an AJAX call to trigger -- is part of the problem. For example Download a file from Servlet using Ajax talks about AJAX storing results in JavaScript memory, which would explain why I get content in my console and not a file.
Try to add code below before Excel::create():
ob_end_clean();
ob_start();
Example code:
ob_end_clean();
ob_start();
Excel::create($filename, function($excel) use($records, $sheetname, $data) {}
This works for me.

Edit in view page or index.cshtml in MVC

I am using MVC 5 and Entity framework 6 (Database First) in my application.
I need to update "value" field in View page\index.cshtml.
Is it possible to use #Html.EditorFor to edit Value field for each Item on single button click?
Here is the code in index.cshtml
<table>
<tr>
<th>
Number
</th>
<th>
Name
</th>
<th>
Value
</th>
<th>
Description
</th>
</tr>
foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.number)
</td>
<td>
#Html.DisplayFor(modelItem => item.name)
</td>
<td>
#Html.EditorFor(modelItem => item.value)
#*#Html.ValidationMessageFor(modelItem => item.value) *#
</td>
<td>
#Html.DisplayFor(modelItem => item.description)
</td>
#* <td>
#Html.ActionLink("Edit", "Edit", new { id=item.id })
</td>*#
</tr>
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
On clicking Save button I should update the data in Value field for any number of rows.
It's done in Database First so action for Edit,View,Details are included in Controller.
You'll have to put everything in a to post the details to the server, then you can manage the posted elements. You'll post a list of itens. Maybe this will help you: How can I post a list of items in MVC

Trying to use laravel pagination breaks my controller/view

I'm trying to get Pagination working in Laravel. I've not used pagination before so am trying to use some examples from the docs and google results. I'm wondering if I need to turn 'pagination' on somewhere in config.
Here's my simple working controller:
public function get_index() {
$locations = Location::all();
return View::make('location.index')->with('locations', $locations)->render();
}
When I try and add pagination like this it breaks:
public function get_index() {
$locations = Location::paginate(5);
return View::make('location.index')->with('locations', $locations)->render();
}
..and I get the error:
Unhandled Exception
Message:
Error rendering view: [location.index]
Trying to get property of non-object
Here's my location.index view:
#layout('layouts.blank')
#section('content')
<div class="row">
<div class="twelve columns">
<div role="main" id="content">
<h3>Locations - All</h3>
#if($locations)
<table class="twelve">
<thead>
<tr>
<th style="text-align: left;">Address</th>
<th>Area</th>
<th>Region</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
#foreach($locations as $location)
<tbody>
<tr>
<td style="text-align: left;">{{ $location->company,', ',$location->add_name,', ',$location->add_city }}</td>
<td> – </td>
<td> – </td>
<td>{{ HTML::link('location/update/'.$location->id, '',array('class'=>"foundicon-edit updateicon")) }}</td>
<td>{{ HTML::link('location/delete/'.$location->id, '',array('class'=>"foundicon-remove warnicon")) }}</td>
</tr>
</tbody>
#endforeach
</table>
#else
Looks like we haven't added any locations, yet!
#endif
<p>{{ HTML::link('location/create', 'Create a location', array('class'=>"small radius button")) }}</p>
</div>
</div>
</div>
#endsection
I hadn't read deeply enough into the subject. It's now working and here's what I had to change in the view:
//from:
#foreach($locations as $location)
//to:
#foreach($locations->results as $location)
That returned just 5 results. Then to add links to the footer of my table I added this HTML/Blade:
<tfoot>
<tr>
<td colspan="5"> {{ $locations->links() }} </td>
</tr>
</tfoot>
Hope someone else benefits as I didn't find this terribly clear in the docs.

Resources