WebFocus, two title columns and merging cells - webfocus

If i have a table in a WebFocus Raport design
+--------+---------+--------+---------+
| left_1 | right_1 | left_2 | right_2 |
+--------+---------+--------+---------+
| v11 | p11 | v21 | v21 |
+--------+---------+--------+---------+
| v12 | p12 | v22 | v22 |
....
How to do a such table with syllabus column titles:
+-------+-------+-------+-------+
| One | Two |
+-------+-------+-------+-------+
| left | right | left | right |
+-------+-------+-------+-------+
| v11 | p11 | v21 | v21 |
+-------+-------+-------+-------+
| v12 | p12 | v22 | v22 |
....
Thank you

Sorry for the delay of the answer :)
To rename columns, with the AS command. Example:
TABLE FILE SYSTABLE
PRINT NAME
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
END
To put the heading columns, you can work with the ACROSS command but it will be more tricky that if u use simply SUBHEAD. With the same example:
TABLE FILE SYSTABLE
PRINT NAME NOPRINT
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
ON TABLE SUBHEAD
"<+0>One<+0> Two"
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
UNITS=IN, PAGESIZE='Letter',
LEFTMARGIN=0.500000, RIGHTMARGIN=0.500000,
TOPMARGIN=0.500000, BOTTOMMARGIN=0.500000,
SQUEEZE=ON, GRID=OFF, ORIENTATION=LANDSCAPE, $
TYPE=REPORT,FONT='ARIAL',SIZE=9,$
TYPE=TABHEADING,HEADALIGN=BODY,$
TYPE=TABHEADING, LINE=1, ITEM=1, COLSPAN=2, SQUEEZE=ON,$
TYPE=TABHEADING, LINE=1, ITEM=2, COLSPAN=2, SQUEEZE=ON,$
ENDSTYLE
END
Hope it helps!

I'm not entirely sure if you load the headers as a field or if that is the field name
But this might help you
Define fields
TITL1/A3 = 'One';
TITL2/A3 = 'Two';
BLANK/A1 = '';
Edit the Left and Right title fields to remove the _1 or _2
Print the fields BY BLANK NOPRINT
Add
ON BLANK SUBHEAD
"
You can also add more rows to the subhead if you need more titles

You can easily do it by embedding HTML/CSS scripts in report(.fex) file.
just add the HTML/css code at the end of the file.
For eg.
-HTMLFORM BEGIN // to start styling your generated report table with HTML/CSS
TABLE tr
td:first-child // applies on 1st row ONLY.It can be td or th.
{
colspan = "2"; //to merge 2 columns
}
-HTMLFORM END //end HTML.
So the first row must have two cells having title "ONE" and "TWO"(in your case), and both cells must have property of colspan = "2"
Also you can refer:
Colspan propery from here
manipulating first row of table from here
Second option is to write the whole code in a file and save it in .htm/.html format and just insert the file in to WEBFOCUS(.fex) file.For eg.
-HTMLFORM BEGIN
-INCLUDE HTML_FILE.HTML
-HTMLFORM END
Hope it helps.Thanks.

Related

Select the opposite of the union data

I had product, vendor, vendor's available day and booking tables. Currently, my search function only can search through vendor available day, but not search through booking table. I used left joins between vendor and vendor available day and compare with the selected day, time and hour. The search result works. How do I search through booking table?
Product Table
id | vendor_id | title | description
Vendor Table
id | name
Vendor Available Table
id | vendor_id | d_day | d_start_hour | d_start_minute | d_end_hour | d_end_minute
Booking Table
id | vendor_id | d_date | d_day | d_start_hour | _start_minute
Below is how I select product based on the selected day, start_hour and start_minute:
SELECT * FROM product
LEFT JOIN ( SELECT * FROM vendor GROUP BY id ) vendor
ON vendor.id = product.vendor_id
LEFT JOIN ( SELECT * FROM vendor_available GROUP BY id) vendor_available
ON vendor_available.vendor_id = product.vendor_id
WHERE ( d_day = '4'
AND (CONCAT(d_start_hour, '.' , d_start_minute) + 0.0) <= '12.15'
AND (CONCAT(d_end_hour, '.', d_end_minute) + 0.0) >= '12.15')
4 is the selected day and 12.15 is the selected hour and selected minute on the client side.
When the user selects 12.15 which is 12.15pm, the query will check which product is available between the vendor available time.
How do I use opposite union with booking table, so that the product which already booked doesn't display to users?
When using LEFT JOIN tbl, it is normal to add this to the WHERE clause (not the ON clause)
AND tbl.id IS NULL
This says that you want to return results only when the is no row in tbl.

jQuery/Javascript - printout the number of occurrences of a particular row

I've a table generated from an external DB.
Using the below line I generate the rows of the table:
var row = $("<div id='row' class='divTableRow'><div class='divTableCell'>"+(i+1)+"</div><div class='divTableCell'>"+fullName+"</div><div class='divTableCell'>"+username+"</div><div class='divTableCell'>"+resName+"</div><div class='divTableCell'>"+finalRating+"</div><div class='divTableCell'>"+date+"</div></div>");
$(".divTable").append(row);
In the table a have a column called username which is basically a unique value to its user.
What I willing to do is to create a column, called for example count which should should the number of occurrences of the value username
Example:
+----+------------+---------------+--------+-------+
| No | Full Name | username | Outlet | Count |
+----+------------+---------------+--------+-------+
| 1 | Stacy Gar | 0649039233 | Out2 | 2 |
+----+------------+---------------+--------+-------+
| 2 | Jeremy Fa | 0349959522 | Out5 | 1 |
+----+------------+---------------+--------+-------+
| 3 | Stacy Gar | 0649039233 | Out1 | 2 |
+----+------------+---------------+--------+-------+
As you can see above in the table the username 0649039233 has bought from Out1 and Out2 that's why it has in the count column 2
Any ideas on how I can achieve similar results in using jQuery or Javascript?
For each row, grab the user ID, then use filter() on the entire table to count the number of its occurrences:
$('tr').each(function() {
var userID = $(this).find('td:nth-child(3)').text(),
count;
count = $('td:nth-child(3)').filter(function() {
return $(this).text() === userID;
}).length;
$(this).find('td:last').text(count);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr><th>No<th>Full Name <th>username <th>Outlet <th>Count
<tr><td>1 <td>Stacy Gar <td>0649039233 <td>Out <td>
<tr><td>2 <td>Jeremy Fa <td>0349959522 <td>Out <td>
<tr><td>3 <td>Stacy Gar <td>0649039233 <td>Out <td>
</table>
When you are creating the row you can save the userName and its occurrence number in this format:
userName1:2;userName2:1;userName3:1;
':' separate the userName and it's occurrence and ';'separate records.
Before all things you must have two array.
var occurrence =[];
var userNames = [];
and when creating each row:
var index = userNames.indexOf(userName);
if(index > 0) // the user name is repeated. we only increase occurrence
{
occurrence[index] = occurrence[index] + 1;
}
else
{
userNames.push(userName);
occurrence.push[1];
}
Now you have what you want:
occurrence of UserNames[i] = occurrence[i];
And you can use like this:
for(i=0;i<$('#yourTable').children('tr').length;i++) //or length-1 if you have header row
{
row = $('#yourTable').children('tr').eq(i); // or eq(i+1) if you have header row
row.children('td').eq(2).html(userNames[i]));
row.children('td').eq(4).html(occurrence[i]));
}

How to set table cell appearance depending on table cell value in Handsontable

I am using Handsontable for PHP with MySQL database.
In my table a have 6 columns as follows:
| Product | Qty. | Good | Damaged | Cut & Torn |
Qty.= Good + Damaged + Cut & Torn
First I'll enter the "Product" and "Quantity" in the table and at that time the values of "Good", "Damaged", "Cut & Torn" will be set automatically to zero. But when I enter a value in any of the cell "Good", "Damaged" or "Cut & Torn" the cell's background will be red until the total values of those three cells ("Good", "Damaged" and "Cut & Torn") will equal to the value of the "Quantity" cell.
Now I need some guide to achieve that via JS ?
Any help will be appreciated.
You may use this solution:
Handsontable.hooks.add('afterRender', function() {
var d = this;
var quantity = d.getDataAtCol(1);
var good = d.getDataAtCol(2);
var damaged = d.getDataAtCol(3);
var cut_torn = d.getDataAtCol(4);
$.each(quantity,function(i,v){
if (+good[i] !== 0 || +damaged[i] !== 0 || +cut_torn[i] !== 0){
if ((+good[i]] + +damaged[i] + +cut_torn[i]) != v ) {
$(d.getCell(i,1)).css({'background':'yellow'});
$(d.getCell(i,2)).css({'background':'red'});
$(d.getCell(i,3)).css({'background':'red'});
$(d.getCell(i,4)).css({'background':'red'});
}
}
});
});

Position output from Google Apps Script to the right of column A

I have a Google spreadsheet script that reads values listed in column A with this code
var values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("master").getDataRange().getValues()
for(n=2;n<values.length;++n){
var data = values[n][0] ; // read values in column A
}
With this data in column A I make api calls and store the data from the API requests in a multidimensional array 'resultRow'
How can I output resultRow in column B,C,D,E,.... so that each row that corresponds with its product # is positioned next to it?
| column A | column B | column C | column D | column E |
| 79327492 | resultRow[0,0] | resultRow[0,1] | resultRow[0,2] |
| 78828388 | resultRow[1,0] | resultRow[1,1] |
| 74629642 | resultRow[2,0] | resultRow[2,1] | resultRow[2,2] | resultRow[2,3] |
I've tried
var range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("master").getRange(3,2,rows,columns); // rows = amount of rows, columns = amount of columns
range.setValues([resultRow]);
But I keep getting this error:
Incorrect range height, was 1 but should be 14
From what I see in your sheet layout, the length of the rows can be different from one row to another.
setValues(2D-Array) requires that each element in the 2D array has exactly the same length so you have to modify your result array so that it meets the requirements.
This can be done in many ways, below is one possible (although not the most elegant) way :
The first function testArray is simply there to create a non homogeneous 2D array to illustrate and provide a use case : it gets non empty values in a sheet and collects it in a 2D array, the sheet I used had a lot of empty cells and random data in it...)
function testArrays(){
var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
Logger.log('original array : \n\n'+JSON.stringify(values)+'\n');
Logger.log('row Length = '+values[0].length+'\n');
var resultArray = [];
for(var n=0;n<values.length;n++){
var rowArray = [];
for(var m=0;m<values[0].length;m++){
if(values[n][m] != ''){
rowArray.push(values[n][m]);
}
}
resultArray.push(rowArray);
}
Logger.log('wrong array : \n'+JSON.stringify(resultArray)+'\n');
resultArray = normalizeTwoDimArray(resultArray,values[0].length);
Logger.log('normalized array : \n'+JSON.stringify(resultArray));
SpreadsheetApp.getActiveSheet().getDataRange().setValues(resultArray)
}
function normalizeTwoDimArray(array,maxLength){
for(var n=0;n<array.length;n++){
if(array[n].length<maxLength){
for(var m = array[n].length ; m < maxLength ; m++){
array[n].push('');
}
}
}
return array;
}

One button each row in a table cell

I am trying to place 2 buttons into a table cell with JavaScript
I have something like this:
var table_cell = document.getElementById("table_cell")
var button_A = document.createElement("input")
button_A.setAttribute("value","BUTTON A")
button_A.setAttribute("type","button")
var button_B = document.createElement("input")
button_B.setAttribute("value","BUTTON A")
button_B.setAttribute("type","button")
table_cell.appendChild(button_A)
table_cell.appendChild(button_B)
buttons get lined up side by side, rather than one up and one down.
I am trying to make it so that there is one button per level
_____________
| _________ |
| |_________| |
| _________ |
| |_________| |
|_____________|
rather than
__________________________
| _________ _________ |
| |_________| |_________| |
|__________________________|
I have tried appending a textnode on to table_cell that contains escape characters like "\r\n" and "&#10&38" but none works.
I would appreciate if there is a solution with JS
How about using a <br> tag between the buttons
table_cell.appendChild(button_A);
table_cell.appendChild(document.createElement('br'));
table_cell.appendChild(button_B);
You could do:
button_A.style.display = 'block';
button_B.style.display = 'block';
But using CSS would probably be best:
input[type="button"] {
display:block;
}
table_cell.appendChild(button_A)
table_cell.appendChild(document.createElement("br"))
table_cell.appendChild(button_B)
Add a line break (<br />) element:
var table_cell = document.getElementById("table_cell");
var button_A = document.createElement("input");
button_A.setAttribute("value","BUTTON A");
button_A.setAttribute("type","button");
var button_B = document.createElement("input");
button_B.setAttribute("value","BUTTON A");
button_B.setAttribute("type","button");
var newline = document.createElement("br"); // <-- Add a newline
table_cell.appendChild(button_A);
table_cell.appendChild(newline); // <-- and append
table_cell.appendChild(button_B);
jsFiddle example

Resources