jqPagination requests for new page - jqpagination

I have a large db table that I want to show to users. I show the info in a table, about 30 rows per page. I want to use jqPagination to allow the users to jump to a different page. So page 1 will show rows 1-30, page 2 will show rows 31-60,... The only example I see are showing how to use it to jump to different section of a page. Is it possible to use jqPagination in a way to request the next 30 rows to a new page?
Thanks in advance!

If you're displaying all table rows to begin with you could use the following code to only show 30 at a time:
$(document).ready(function() {
// select the table rows
$table_rows = $('.table-example tbody tr');
var table_row_limit = 30;
var page_table = function(page) {
// calculate the offset and limit values
var offset = (page - 1) * table_row_limit,
limit = page * table_row_limit;
// hide all table rows
$table_rows.hide();
// show only the n rows
$table_rows.slice(offset, limit).show();
}
$('.pagination').jqPagination({
max_page: $table_rows.length / table_row_limit,
paged: page_table
});
// set the initial table state to page 1
page_table(1);
});
Table pagination example.
If you don't display all rows to begin with, you could adapt this code to fetch the rows from your system using AJAX instead of showing / hiding.

Related

Display first ten cols of Altair chart if no user selection?

My graph contains 90 rows of different companies. It's controlled by a dropdown menu that allows users to select an individual company. However, until a user selects a value from the dropdown, ALL the rows are displayed all my graph, which looks messy. Is there anyway to show only the first company by default? Or the first ten companies? Thanks.
Current Output.
Desired Output
I haven't found any solutions thus far. Here is my current code.
dropdown_list = df["Name"].sort_values().unique().tolist()
dropdown = alt.binding_select(options=[None] + dropdown_list, labels = ['All'] + dropdown_list, name = "Operator")
selection = alt.selection_single(fields=["Name"], bind=dropdown)
`(alt.Chart(df).mark_circle(opacity=1, size = 150).transform_window(id='rank()',groupby=['Variable']).encode(alt.X('Percentage:O', sort='ascending', axis=alt.Axis(ticks=False, grid=False)),
alt.Y('Name:N'),
color=alt.Color("Variable:N", scale=alt.Scale(range=cp.CALITP_CATEGORY_BRIGHT_COLORS), legend=None),
tooltip = ['Name', 'Variable'])
.properties(title = "Title Here").add_selection(selection).transform_filter(selection))`

Code not saving when trying to wrap promoted tiles in SharePoint Online

Apologies for another question re this, but I've tried so hard to get this working (I'm fairly new to SharePoint, don't have extensive coding knowledge, but know HTML and generally alright at trouble shooting).
We are using SharePoint online and we have SharePoint Tiles. We have recently added a few more tiles and it's obviously not wrapping these tiles, thus having to scroll right to access some.
I have found the code for wrapping the tiles here and when editing the page source, it appears to be working... until I save it. The code I put in is stripped out when I next go to the content editor.
I've read a few pages on it and have tried things such as the content editor web part, but for the life of me cannot get it to work.
If anyone would know if there's a step to step guide to ensure wrapped tiles are saved, I may be able to get it to work.
Any help is greatly appreciated.
If it changes anything, we use SharePoint online that is part of our Office 365 account.
Add the following code into script editor web part in the page.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Update this value to the number of links you want to show per row
var numberOfLinksPerRow = 6;
// local variables
var pre = "<tr><td><div class='ms-promlink-body' id='promlink_row_";
var post = "'></div></td></tr>";
var numberOfLinksInCurrentRow = numberOfLinksPerRow;
var currentRow = 1
// find the number of promoted links we're displaying
var numberOfPromotedLinks = $('.ms-promlink-body > .ms-tileview-tile-root').length;
// if we have more links then we want in a row, let's continue
if (numberOfPromotedLinks > numberOfLinksPerRow) {
// we don't need the header anymore, no cycling through links
$('.ms-promlink-root > .ms-promlink-header').empty();
// let's iterate through all the links after the maximum displayed link
for (i = numberOfLinksPerRow + 1; i <= numberOfPromotedLinks; i++) {
// if we're reached the maximum number of links to show per row, add a new row
// this happens the first time, with the values set initially
if (numberOfLinksInCurrentRow == numberOfLinksPerRow) {
// i just want the 2nd row to
currentRow++;
// create a new row of links
$('.ms-promlink-root > table > tbody:last').append(pre + currentRow + post);
// reset the number of links for the current row
numberOfLinksInCurrentRow = 0;
}
// move the Nth (numberOfLinksPerRow + 1) div to the current table row
$('#promlink_row_' + currentRow).append($('.ms-promlink-body > .ms-tileview-tile-root:eq(' + (numberOfLinksPerRow) + ')'));
// increment the number of links in the current row
numberOfLinksInCurrentRow++;
}
}
});
</script>
We can also use CSS style below in script editor web part in the page to achieve it.
<style>
.ms-promlink-body {
width: 960px;
}
</style>

How to calculate the number of displayed rows in a repeat control

In my XPages application I am displaying a list of objects via the xp:repeat control.
I also use the xe:pagerAddRows control to add an X numbers of rows to the repeat control.
In the text of the xe:pagerAddRows control I want to display how many more items there are. Therefor I need to know the number of rows currently displayed in the repeat control.
How must I do this?
I am using this:
var text = strings["btn_show_more"]
var dv = getComponent('rptHistory');
return text + " (" + (dv.getRowCount() - dv.getRows()) + ")";
More on the add rows control can be read here https://xcellerant.net/2013/08/07/xpages-data-views-5-pager-add-rows-control/

How to scrape data from a website, that has a table that needs scrolling to display all data?

This website has a table that only display 100 rows at a time. You need to scroll further to display more rows. I'm using Node.js and Horseman + PhantomJS to scrape data, but I want to find an efficient way of scraping the whole table, not just 100 rows at a time.
var h = new Horseman({timeout: 20000});
h
.open(<<link>>)
.waitForSelector("table.GridListings")
.text("td.ListingID")
.then(function(data) {
console.log(data);
});
What further modifications can I do, to scroll through the entire table and fetch all data?
You can use .scrollTo(top, left) to scroll to the bottom of the page and keep doing it until no new content is being loaded for some time.
Then you can check the table that should be populated with all of the fields.
Use phantomjs instance to evaluate javascript and scrooll to windows bottom
.evaluate(function () {
window.scrollTo(0,document.body.scrollHeight);
});
I think, in this case you should scroll (.scrollTo(top, left) method) and wait (probably, .waitFor(fn, [arg1, arg2,...], value) method) for table being repopulated. I guess, you should repeat the actions until number of rows in the table equals to "Number of Listings" in the "Results Summary" block.

LWUIT Table Layout embedded TextAreas

my goal is to display a Table through parsing an XML file.
I'm using a SAX Parser and the content has multirows and I want
the table width to fit to the display. Of course Y_AXIS scrolling would be ok.
Right now, I'm using the HTMLTableModel of src/com/sun/lwuit/html/ and it's corresponding HTMLTable. For this I declared it's methods public so I can access them. This works fine so far. This allows me to declare tables without knowing their size prematurely.
To allow multirows, I'm embedding TextAreas in the Cells.
Now the problem: The HTMLTable t needs t.setScrollableY(true), or else not all rows are shown.
This causes the table to be a bit to large in X direction, so the right border isn't shown.
Also the bottom border isn't shown all the time.
The container in which the table is embedded has BorderLayout.Y_AXIS.
Things I tried:
t.setPreferredW(mainContainer.getLayoutWidth()); This does reduce the size of the table, but then the table doesn't show all it's rows, like without t.setScrollableY(true).
t.setLayout(new BoxLayout(BoxLayout.Y_AXIS)) this causes an java/lang/ClassCastException.
Any ideas? Thanks in advance.
Excerpt from my code:
} else if (qName.equalsIgnoreCase("td")) {
if (sb.length() > 0) {
String sbt = new String(sb);
sb.delete(0, sb.length());
TextArea c = new TextArea(sbt);
c.setEditable(false);
c.getStyle().setFont(smallFont);
table.addCell(c, false, null);
}
} else if (qName.equalsIgnoreCase("tr")) {
debugPrint("Row closed.");
table.commitRow();
} else if (qName.equalsIgnoreCase("table")) {
HTMLTable t = new HTMLTable(table);
//without scrollable Y not all table rows are shown
t.setScrollableY(true);
//t.setPreferredW(screenWidth);
//this is verboten.
t.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.addComponent(t);
tableBool = false;
You can't change the layout of the table from table layout otherwise it will not be a table.
It should be possible to get the table to fill the width of a parent BoxLayout_Y by assigning width percentages to table columns up to 100% e.g. for a 3 column table return assign 33, 33 & 44.
This can be achieved by subclassing table and overriding the method:
protected TableLayout.Constraint createCellConstraint(Object value, int row, int column) {
TableLayout.Constraint c = super.createCellConstraint(value, row, column);
c.setWidthPercentage(whateverYouWant);
return c;
}

Resources