There is not many useful examples with jQuery jscroll and it is a fact it doesn't work with table rows by default because it puts the results into a div element which screws up the table.
I had this HTML template
<table class="table responsive-table-list">
<thead>
<tr>
<th>label 1</th>
<th>label 2</th>
<th>label 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>data 1.1</td>
<td>data 1.2</td>
<td>data 1.3</td>
</tr>
<tr>
<td>data 2.1</td>
<td>data 2.2</td>
<td>data 2.3</td>
</tr>
<tbody>
</table>
How can I make it jScrollable?
You need your own controller which provides the data. This is not part of this solution. The output in this case has to be HTML and has to contain the next X rows of the table.
The HTML template wrapped with an extra div. The next page link (pointing to the controller) is added as a new row. jscroll will remove the A and the TD tags but will not remove the TR as it is not aware of it. We have to do it later otherwise the empty TR tags break the HTML.
I pass the auto-trigger and the loading-html in the data argument which I can access from the javascript code.
I use nextPageLoad class in the A tag which helps me to recognize the jscroll related link.
<div class="jscroll" data-auto-trigger="true" data-loading-html="Loading..">
<table class="table responsive-table-list">
<thead>
<tr>
<th>label 1</th>
<th>label 2</th>
<th>label 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>data 1.1</td>
<td>data 1.2</td>
<td>data 1.3</td>
</tr>
<tr>
<td>data 2.1</td>
<td>data 2.2</td>
<td>data 2.3</td>
</tr>
<tr>
<td colspan="3">
Next page
</td>
</tr>
<tbody>
</table>
</div>
the javascript code. The debug is activated!
var EndlessScroll = (function ($) {
function init() {
var $scrollEl = $('.jscroll');
var autoTrigger = $scrollEl.data('auto-trigger');
var loadingHtml = $('<span>');
loadingHtml.text($scrollEl.data('loading-html'));
$scrollEl.jscroll({
loadingHtml: loadingHtml[0].outerHTML,
padding: 20,
autoTrigger: autoTrigger,
nextSelector: '.nextPageLoad',
callback: function (data) {
var $table = $('.jscroll table tbody');
// moves the new elements from the jscroll div to the table
$('.jscroll-added tr').appendTo($table);
// removes the empty tr encapsulated the jscroll pagination
var rows = $table.find('tr');
rows.each(function(idx, el){
if ($(el).children().length === 0) {
$(el).remove();
}
});
},
debug: true
});
}
return {
init: init
};
})(jQuery);
$(EndlessScroll.init);
Related
<tbody>
<tr th:each="bean , beanStat : ${list}">
<td class="text-center" th:text="${beanStat.size-beanStat.count+1}+(${paging.cri.page}-1)*${cri.perPageNum}" >1</td>
<!-- paging.totalcount -->
<!-- <tr th:each="bean , beanStat : ${list}">
<td class="text-center" th:text="${beanStat.size-beanStat.count+1}+(${paging.cri.page}-1)*${cri.perPageNum}" >1</td>
First of all, I'm sorry for not speaking English well.
I want to number the articles, but I want to number them in reverse order.
I think you can do it like below in jsp
In thymeleaf, I wonder how to do this in reverse order (is there an index?)
Total number of records - ( (Current page number - 1) * I think it is the number of records displayed per page.
${(totalCount - status.index) - ( (currentPage - 1) * displayNum ) }
I implemented it like this, but I wonder if there is such a part as status.index in the thymeleaf.
enter image description here
There is an equivalent to your JSP approach in Thymeleaf - a set of iteration tracking attributes you can use when processing a list.
Assuming you have a Java list like this:
List<String> list = new ArrayList<>();
list.add("One");
list.add("Two");
list.add("Three");
Then you can use the following Thymeleaf:
<table>
<thead>
<tr>
<th>Number</th>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr th:each="item, iterStat : ${list}">
<td th:text="${iterStat.size - iterStat.count +1}"></td>
<td th:text="${item}"></td>
</tr>
</tbody>
</table>
This generates:
<table>
<thead>
<tr>
<th>Number</th>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>One</td>
</tr>
<tr>
<td>2</td>
<td>Two</td>
</tr>
<tr>
<td>1</td>
<td>Three</td>
</tr>
</tbody>
</table>
Update
If you want to add paging into the calculation, then your Java code needs to know:
current page number
maximum number of rows per page (there may be fewer in the final page)
total number of records (all pages)
Let's assume I pass those 3 values from Java to my Thymeleaf model with some new data:
List<String> list = new ArrayList<>();
list.add("Alfa");
list.add("Bravo");
list.add("Charlie");
list.add("Delta");
list.add("Echo");
int currentPage = 1;
int rowsPerPage = 5;
int totalRecords = 9;
Now, the Thymeleaf changes to this:
<table>
<thead>
<tr>
<th>Number</th>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr th:each="item, iterStat : ${list}">
<td th:text="${totalRecords - (currentPage * rowsPerPage)
+ rowsPerPage - iterStat.count +1}"></td>
<td th:text="${item}"></td>
</tr>
</tbody>
</table>
For page 1 this generates:
<tbody>
<tr>
<td>9</td>
<td>Alfa</td>
</tr>
<tr>
<td>8</td>
<td>Bravo</td>
</tr>
<tr>
<td>7</td>
<td>Charlie</td>
</tr>
<tr>
<td>6</td>
<td>Delta</td>
</tr>
<tr>
<td>5</td>
<td>Echo</td>
</tr>
</tbody>
For page 2 (the final 4 items), we have:
List<String> list = new ArrayList<>();
list.add("Foxtrot");
list.add("Golf");
list.add("Hotel");
list.add("India");
int currentPage = 2;
int rowsPerPage = 5;
int totalRecords = 9;
Note: Only the current page number has changed. The rows per page and the total records: those values remain the same across all pages.
And the same Thymeleaf template generates this:
<tbody>
<tr>
<td>4</td>
<td>Foxtrot</td>
</tr>
<tr>
<td>3</td>
<td>Golf</td>
</tr>
<tr>
<td>2</td>
<td>Hotel</td>
</tr>
<tr>
<td>1</td>
<td>India</td>
</tr>
</tbody>
I am new to Laravel and trying to create a simple sortable table using JQuery.
I have the following in my view:
<table id="dtBasicExample" class="table">
<thead>
<tr>
<th scope="col">Submission ID</th>
<th scope="col">Advisor ID</th>
<th scope="col">Advisor Name</th>
<th scope="col">Advisor Email</th>
<th scope="col">Link</th>
<th scope="col">Employer Name</th>
<th scope="col">Received Date</th>
<th scope="col">Plan Renewal Date</th>
<th scope="col">Status</th>
<th scope="col">Copy</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
#foreach($plans as $plan)
<tr>
<td> {{$plan->id}}</td>
<td> {{$plan->advisor_id}}</td>
<td> {{$plan->advisor->name}}</td>
<td> {{$plan->advisor->email}}</td>
<td>Click Here</td>
<td>{{$plan->employer_name}}</td>
<td>{{$plan->updated_at}}</td>
<td>{{$plan->medical_plan_renewal_date}}</td>
<td>{{$plan->status}}</td>
<td>Copy</td>
<td>Delete</td>
#endforeach
</tr>
</tbody>
</table>
I have the following in my app.js file:
$(document).ready(function() {
$("#dtBasicExample").DataTable();
$(".dataTables_length").addClass("bs-select");
});
I have the following in my app.css file:
table.dataTable thead .sorting:after,
table.dataTable thead .sorting:before,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_asc_disabled:after,
table.dataTable thead .sorting_asc_disabled:before,
table.dataTable thead .sorting_desc:after,
table.dataTable thead .sorting_desc:before,
table.dataTable thead .sorting_desc_disabled:after,
table.dataTable thead .sorting_desc_disabled:before {
bottom: .5em;
}
I imagine I am wrong on where to put the JS and/or CSS. My understanding is the bootstrap.js file pulls in JQuery and the app.js file pulls in the bootstrap.js file. Also, my app.css (in public folder) is highlighted red when I open it.
Laravel Snappy works great, but trying to fix this
The headers are good, but the table itself is not splitting and starting underneath the headers of the second page. Is this fixable? I am using the adminLTE theme.
Seen this page, but this does not solve it for me: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2367
Current code:
<table class="table table-striped table-bordered tree">
<thead>
<tr>
<th></th>
<th>Cables</th>
<th>Customer</th>
<th>Supplier</th>
<th>Load in</th>
<th>Load out</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<tr>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
</tr>
</tbody>
</table>
.tree {
page-break-inside: avoid;
}
add this code in style. Hope that will be work
.page-break {
page-break-after: always;
}
.page-break:last-child {
page-break-after: avoid;
}
$(document).ready(function() {
$("#grid").kendoGrid({
height: 550,
sortable: true
});
});
<link href="http://kendo.cdn.telerik.com/2014.1.318/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2014.1.318/js/kendo.all.min.js"></script>
<div id="example">
<table id="grid">
<colgroup>
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th data-field="make" data-hidden="true">Car Make</th>
<th data-field="model">Car Model</th>
<th data-field="year">Year</th>
<th data-field="category">Category</th>
<th data-field="airconditioner">Air Conditioner</th>
</tr>
</thead>
<tbody>
<tr>
<td>Volvo</td>
<td>S60</td>
<td>2010</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Audi</td>
<td>A4</td>
<td>2002</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>BMW</td>
<td>535d</td>
<td>2006</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>BMW</td>
<td>320d</td>
<td>2006</td>
<td>Saloon</td>
<td>No</td>
</tr>
<tr>
<td>VW</td>
<td>Passat</td>
<td>2007</td>
<td>Saloon</td>
<td>No</td>
</tr>
<tr>
<td>VW</td>
<td>Passat</td>
<td>2008</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Peugeot</td>
<td>407</td>
<td>2006</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Honda</td>
<td>Accord</td>
<td>2008</td>
<td>Saloon</td>
<td>No</td>
</tr>
<tr>
<td>Alfa Romeo</td>
<td>159</td>
<td>2008</td>
<td>Saloon</td>
<td>No</td>
</tr>
<tr>
<td>Nissan</td>
<td>Almera</td>
<td>2001</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Mitsubishi</td>
<td>Lancer</td>
<td>2008</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Opel</td>
<td>Vectra</td>
<td>2008</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Toyota</td>
<td>Avensis</td>
<td>2006</td>
<td>Saloon</td>
<td>No</td>
</tr>
<tr>
<td>Toyota</td>
<td>Avensis</td>
<td>2008</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Toyota</td>
<td>Avensis</td>
<td>2008</td>
<td>Saloon</td>
<td>Yes</td>
</tr>
<tr>
<td>Audi</td>
<td>Q7</td>
<td>2007</td>
<td>SUV</td>
<td>Yes</td>
</tr>
<tr>
<td>Hyundai</td>
<td>Santa Fe</td>
<td>2012</td>
<td>SUV</td>
<td>Yes</td>
</tr>
<tr>
<td>Hyundai</td>
<td>Santa Fe</td>
<td>2013</td>
<td>SUV</td>
<td>Yes</td>
</tr>
<tr>
<td>Nissan</td>
<td>Qashqai</td>
<td>2007</td>
<td>SUV</td>
<td>Yes</td>
</tr>
<tr>
<td>Mercedez</td>
<td>B Class</td>
<td>2007</td>
<td>Hatchback</td>
<td>Yes</td>
</tr>
<tr>
<td>Lancia</td>
<td>Ypsilon</td>
<td>2006</td>
<td>Hatchback</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
Initializing from HTML table, how can I specify a column to be hidden? I need to access the data for that column in JS, but don't want to have that data visible to the end user.
http://demos.telerik.com/kendo-ui/grid/from-table
I've tried to use the attribute: data-hidden="true" on the th tag (data-field is also on th tag, as it is in the demo), but it's not working.
Note, I'd like to be able to specify the hidden option as an html attribute, if possible.
unfortunately you can't use the attribute hidden when initializing from an HTML table:
http://docs.telerik.com/kendo-ui/web/grid/introduction#create-a-grid-from-an-existing-html-table
Relevant quote:
When creating the Grid from an existing table, the following column
settings can be defined via HTML attributes:
data field names via data-field attributes
column widths via width styles applied to the respective elements
define data type via data-type attributes
define a column template via data-template attributes
enable or disable the column menu via data-menu attributes
enable or disable sorting via data-sortable attributes
enable or disable filtering via data-filterable attributes
enable or disable grouping via data-groupable attributes
All attributes should be applied to the <th> elements, except the column width styles.
All other column-related settings cannot be defined via HTML attributes in the <table>. If such settings must be used (e.g. commands, locking, editors, etc.) then the above attribute configuration should be abandoned and all settings should be included in the Grid's Javascript initialization statement (when using declarative widget initialization, the column properties should be set via the data-columns attribute).
For more info on that:
http://www.telerik.com/blogs/mvvm_declarative_initialization_and_html5_data_attributes
This is a good overview of declarative initiation in kendo.
http://www.telerik.com/forums/declarative-initialization-of-the-kendo-ui-grid
This post is a good example of declaritive initialization specific to grids
With that being said, Here's a quick and dirty workaround if you are seriously married to the plain old HTML format (this would allow you to set hidden via a data attribute, rather than hiding individual columns--which may or may not be important to you):
$(document).ready(function() {
var columns = $('#grid th'),
grid = $("#grid").kendoGrid({
height: 550,
sortable: true
}).data("kendoGrid");
for(var i =0; i < columns.length; i++){
if($(columns[i]).data("hidden") === true){
grid.hideColumn($(columns[i]).data("field"));
}
}
});
http://jsbin.com/mapadu/edit?html,js,output
You can hide column after the initialization of the widget. using the data field string
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
height: 550,
sortable: true
});
var grid = $("#grid").data("kendoGrid");
grid.hideColumn("airconditioner");
});
</script>
Here is a working demo, but user can always check the source of the page and view the data because this only set the style of the <td> to display:none
I'm building a mobile real estate website for my wife's business using Tablesorter to sort by price. It works fine for 6 digit numbers (including $s and commas), e.g. $600,000. However it fails when confronting a 7 digit number, e.g. $1,295,000.
In my
<script type="text/javascript" id="js">$(document).ready(function() {
$("table").tablesorter({
// sort on the second column, order asc
sortList: [[1,0]],
headers: {
1: { sorter: 'digit' } // column number, type
}
});
});
<table cellspacing="2" class="tablesorter { 0: { sorter: false}, 1: {sorter: true} }">
<thead>
<tr>
<th width="158" class="headerempty">Property</th>
<th width="130" class="{'sorter':'currency'}">Sort by Price</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="../sales/29 Laurel Way/prepped_images/29lw-for_mobile.jpg" title="Tap for Details" alt="29 Laurel Way" width="150" height="100" border="0"></td>
<td class="{'sorter':'currency'}">$329,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Aetna Lane/al_for_Mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$175,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Atop Smith Hill/prepped/ash_mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$1,295,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Beech Hill/bh_mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$595,000</td>
</tr>
<tr class="odd">
<td class="{'sorter':'currency'}"><img src="../sales/Bluefield/b_mobile.jpg" width="150" height="100"></td>
<td>$299,000</td>
</tr>
</tbody>
</table>
Any thoughts on solving this one? Many thanks in advance, clpix
Constructions like td class="{'sorter':'currency'}" make me scary. You probaly should define table with class sortable and init table sorted in JS using this class, and define sorting parameters in constructor:
$(".sortable").tablesorter({
// sort on the second column, order asc
sortList: [[1,0]],
headers: {
1: { sorter: 'currency' } // column number, type
}
});
<table class='sortable'>
<tr>
<td>$1.000.000</td>
</tr>
......
</table>
And check out delimeter . or ,
This code work fine.