You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.4 KiB
114 lines
3.4 KiB
// scrolltable.js - scroll functions for dataTable
|
|
|
|
function scrollAndFocus(rootId, tableId, txtId) {
|
|
scrollToBottom(rootId + ":" + tableId);
|
|
$(rootId +":" + txtId).focus();
|
|
}
|
|
|
|
function scrollToBottom(idDataTable) {
|
|
pTable = digestTable(idDataTable);
|
|
|
|
scrollToRow(pTable, 9999);
|
|
}
|
|
|
|
function digestTable(idDataTable) {
|
|
pTable = {
|
|
id: idDataTable
|
|
}
|
|
pTable.jqId = '#' + idDataTable.replaceAll(':', '\\:');
|
|
pTable.jqData = pTable.jqId + "_data";
|
|
pTable.heignt = $(pTable.jqId + " .ui-datatable-scrollable-body").height();
|
|
//var lichildren = $(pTable.jqId).children("tr");
|
|
var lichildren = $(pTable.jqId).find("tr");
|
|
pTable.itemHeight = lichildren.height();
|
|
pTable.itemCount = lichildren.length;
|
|
pTable.visibleItemCount = pTable.height / pTable.itemHeight;
|
|
return pTable;
|
|
}
|
|
|
|
|
|
function scrollToRow(pTable, selItem) {
|
|
var maxScrollItem = pTable.itemCount - pTable.visibleItemCount;
|
|
var scrollTopInPx;
|
|
if(selItem >= maxScrollItem)
|
|
{
|
|
// scroll table to the bottom
|
|
scrollTopInPx = pTable.itemCount * pTable.itemHeight;
|
|
}
|
|
else if(selItem < 2)
|
|
{
|
|
// scroll table to the top
|
|
scrollTopInPx = 0;
|
|
}
|
|
else
|
|
{
|
|
// scroll selected item to the 1.2 th position
|
|
scrollTopInPx = (selItem - 1.2) * pTable.itemHeight;
|
|
}
|
|
|
|
//$(pTable.jqId + " .ui-datatable-scrollable-body").animate({scrollTop:scrollTopInPx, duration: 20}, scrollTopInPx);
|
|
$(pTable.jqId + " .ui-datatable-scrollable-body").scrollTop(scrollTopInPx);
|
|
}
|
|
|
|
/**
|
|
* This function scrolls the selected Item of a
|
|
* <p:dataTable id="idDataTable" selectionMode="single"
|
|
* into the visible area
|
|
* <p:dataTable renderes to a scroll-container with the css-class: ui-datatable-scrollable-body (inside the element with the id : "idDataTable")
|
|
* and to a container holding all items with the id: "idDataTable"_data
|
|
*
|
|
* @param idDataTable z.B.: idForm:idDataTable
|
|
*/
|
|
function autoScrollPDatatable(idDataTable)
|
|
{
|
|
// for selection in JQuery the ids with : must be encoded with \\:
|
|
var primfcid = idDataTable.replace(':', '\\:');
|
|
var idDataTbl = '#' + primfcid;
|
|
var idDataContainer = idDataTbl + "_data";
|
|
|
|
var totalHeight = $(idDataTbl + " .ui-datatable-scrollable-body").height();
|
|
var lichildren = $(idDataContainer).children("tr");
|
|
var itemHeight = $(idDataContainer).children("tr").height();
|
|
var anzItems = lichildren.length;
|
|
var anzVisItems = totalHeight / itemHeight;
|
|
var selItem = detectDataTableScrollPos(lichildren);
|
|
if(selItem == -1)
|
|
{
|
|
// no selection found...
|
|
return;
|
|
}
|
|
|
|
var maxScrollItem = anzItems - anzVisItems;
|
|
var scrollTopInPx;
|
|
if(selItem >= maxScrollItem)
|
|
{
|
|
// scroll table to the bottom
|
|
scrollTopInPx = maxScrollItem * itemHeight;
|
|
}
|
|
else if(selItem < 2)
|
|
{
|
|
// scroll table to the top
|
|
scrollTopInPx = 0;
|
|
}
|
|
else
|
|
{
|
|
// scroll selected item to the 1.2 th position
|
|
scrollTopInPx = (selItem - 1.2) * itemHeight;
|
|
}
|
|
|
|
$(idDataTbl + " .ui-datatable-scrollable-body").animate({scrollTop:scrollTopInPx}, scrollTopInPx);
|
|
}
|
|
|
|
function detectDataTableScrollPos(liChildren)
|
|
{
|
|
for (i=0;i< liChildren.length;++i)
|
|
{
|
|
var chd = liChildren[i];
|
|
var x = chd.getAttribute("aria-selected");
|
|
if(x === "true")
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
} |