avoid - aggregation in ag-grid - javascript

i have ag-grid. This is the column structure -
account share qty
i'm grouping by account (rowGroup = true). I have this sample data -
account
share
qty
234
xny
4
234
ghy
3
this appears as
account
share
qty
234
0
xny
4
ghy
3
note that 0 comes for qty. this is because i havenot provided any aggregateFunction to colDef.
I want that qty cell to be empty for group level records (instead of showing a zero). is there a way to do it?

I'm not sure if this is the correct way but I was able to solve this by checking if the row is a group level row in my value formatter.
if the row is a group level row, i would return an empty string. otherwise, i would invoke the formatting function to show formatted data.

Related

Condition Based Result In another Column

I want to give condition in column B based on Column A data.
Example ColA have data Score i.e 80,90,40,50,60,70
and I want Column B should come If ColA=80 then "Good",90 then "Excellent",60 then Average
I am trying on it but output is not coming ok

AngularJS - Sorting ng-repeat on string with numbers in them

I have a list of objects in a table-view i would like to sort properly.
Amongst other things, my objects contain a name-field. This name field can also contain numbers, so for example:
Chairman
Seat 1
Seat 2
Seat 3
Seat 11
Seat 12
Seat 23
Secretary
This is however sorted like this:
Chairman
Seat 1
Seat 11
Seat 12
Seat 2
Seat 23
Seat 3
Secretary
This doesn't seem like a natural way of sorting my list when sorting by name.
Now i'm using the ng-repeat like this:
seat in seats | orderBy:orderField:orderReverse track by seat.id
Where orderfield is some variable that is set when clicking the table header and orderReverse is too for reversing.
I've tried making a custom filter to makes sure it behaves properly but i failed. It seems that Javascript just won't order it normally unless i break up the string. But i'd rather not because the data is often updated by polling. Another way would be to force leading zero's but since users are entering this stuff manually i'm not sure if i should.
Also, its not only names with numbers in them, so i can't just completely cut them off
So, any suggestions on how to make this list show normally?
Edit: cleared up some info about the problem.
You can use a custom sort function with orderBy (it can take custom sorting function too)
define a sort function in your controller:
$scope.sorter = function (a){
return parseInt(a.replace( /^\D+/g, '')); // gets number from a string
}
and then in your template
seat in seats | orderBy:sorter track by seat.id
Edit as per the modified problem statement:
Do manual sorting in controller instead of with ng-repeart using naturalSort
$scope.seats = [{"id": "Seat 12"},{"id": "Seat 3"},{"id": "Seat 1"},{"id": "Seat 2"},{"id": "Secretary"}];
$scope.seats.sort(function(a,b) {
return naturalSort(a.id, b.id);
})
or check this angular module http://blog.overzealous.com/post/55829457993/natural-sorting-within-angular-js and the fiddle demonstrating it - http://jsfiddle.net/wE7H2/3/

How to delete selected checkbox rows in an Oracle APEX Classic Report using Ajax

Within Oracle APEX v4.2.2, I have a simple classic report that has as a first column, a checkbox f50 setup attached to the table's ID column, which will allow a user to check all or specific rows and remove these records from the report/table.
An example report might be something like:
ID Col2 Col3 Col4
----------------------------
1 10 20 30
2 5 8 9
3 92 88 12
4 1 2 44
5 95 77 88
The requirement I am after is that I want to perform this whole process of checking the IDs and the removal of these records done without having to submit the whole page but would like it done via an AJAX method using apex.process.server if possible.
UPDATE: Just a bit more background on this requirement based on the report I am attempting to hook this apex.process.server checkbox IDs, i.e.:
ID Report Column above within Report Attributes heading looks like this:
<input type="checkbox" label="Select Code" onclick="$f_CheckFirstColumn(this)" />
Drilling down into this ID column under HTML Expression is the following:
<input type="checkbox" #ID# value="#ID#" name="f50" id="f50_#ROWNUM#"/>
Region Source:
SELECT A.ID,
A.REQ_NO COL2,
A.CODE_ID||apex_item.hidden(20, A.CODE_ID)||apex_item.hidden(30, A.ID) COL3,
GROUP_VALUE COL4
FROM MY_TABLE A
WHERE A.REQ_NO = :REQ_NO
I believe inorder to have APEX store the values within the apex_application.g_f50.countarray of the IDs to be removed, the page needs to be submitted.
Using apex.process.server, can the ids, as they are checked, be passed as a JavaScript array to an on demand process that will then use these ids to perform the required delete operation?
How can I achieve the above via an AJAX means (no page refresh at all)?
Given this query for a report
select
"EMPNO",
"ENAME",
apex_item.checkbox2(2, 0) check1,
apex_item.checkbox2(3, 0) check2,
apex_item.checkbox2(4, 0) check3
from EMP
With EMPNO set to "Hidden" - so it'll generate a hidden input item appended to the last column.
To update a certain record you'll need a PK and a value to update the row with. That is why I'm using EMPNO. I'll pass that to the on-demand process.
function selectorToArray(pSelector){
function getVal(pNd){
switch ( pNd.nodeName ) {
case "INPUT":
switch ( pNd.type ) {
case "checkbox":
return $(pNd).prop("checked");
break;
default:
return $(pNd).val();
};
break;
default:
return $(pNd).val()
};
};
var lArray = [];
$(pSelector).each(function(){
lArray.push(getVal(this));
});
return lArray;
};
The function selectorToArray will fetch the values for the given selector to an array and get the value. As you might know, you can pass values to a process with x01, x02, ... But there are also arrays: f01, f02,...
With the following code you can send values over to the ondemand process:
function sendCheckboxes(){
var lf01 = [], lf02 = [], lf03 = [], lf04 = [];
lf01 = selectorToArray("input[name=f01]");
lf02 = selectorToArray("input[name=f02]");
lf03 = selectorToArray("input[name=f03]");
lf04 = selectorToArray("input[name=f04]");
apex.server.process("PROCESS_CHECKBOXES", {f01: lf01, f02: lf02, f03: lf03, f04: lf04});
};
You can use those just like you would otherwise: loop over them:
DECLARE
l_pk VARCHAR2(30);
l_check1 VARCHAR2(30);
l_check2 VARCHAR2(30);
l_check3 VARCHAR2(30);
BEGIN
-- f01: PK
-- f02: checkbox values column1
FOR i IN 1..apex_application.g_f01.count
LOOP
l_pk := apex_application.g_f01(i);
l_check1 := apex_application.g_f02(i);
l_check2 := apex_application.g_f03(i);
l_check3 := apex_application.g_f04(i);
apex_debug.message('Record with PK '||l_pk||': check1? '||NVL(l_check1, 'NO')||': check2? '||NVL(l_check2, 'NO')||': check3? '||NVL(l_check3, 'NO'));
END LOOP;
END;
In your code, there are 3 item arrays: f20, f30 and f50. f30 holds the row PK value, while f50 is used for the checkbox.
Don't be fooled by the array naming. Apex itself uses the f## arrays for submission, true enough. And your items with name f50 will indeed be in array g_f50 on page submit.
You can however also use arrays f01 to f20 (don't think it goes up to 50) for ajax calls! They're a great addition to the variables x01-x20!
When using the arrays to send a bulk of values to your process, instead of one-by-one, I think it's most useful to not just send an array of PK values, with a position-matched array of values to interact with. This isn't as valuable when you use a report without pagination though, but still. With pagination, the idea is that you don't really know what set of data was just interacted with. Of 100 records, 10 rows were presented. Of those 10 rows, 6 were checked on render, and on submit only 5 are. Which ones are checked and which ones are unchecked. Knowing which 5 are checked doesn't mean you know the unchecked ones.
When you include a PK column however, you'll always have those 10 rows and you're able to identify clearly which records has been checked or unchecked.
For instance, 10 records in your report will (=should!) mean that 10 values are put in an array (eg l_f01) with the PK value and 10 more values are put in another array (eg l_f02) with eg a checked indicator. So when passing those on to the on-demand process, you'll be able to loop over array f01 reliably, and fetch the checked or unchecked indicator from array f02 with your current index variable used for f01.
Plainly put, you're building up 2 arrays with this sort of value set:
f01 - IDs | f02 - checkeds
----------|---------------
4520 | false
4521 | true
4527 | false
4561 | true
4578 | true

Create table with nested rows for each parent row

Table 1
orderid customerName totalCost
----------------------------------
1 Jonh £200.00
2 Ringo £50
Table 2
orderlineid orderid productName productPrice Quantity
-------------------------------------------------------
1 1 Product1 £150 1
2 1 Product2 £50 1
3 2 Product3 £50 1
Table 3
orderid customerName totalCost
---------------------------------------
1 John £200
---------------------------------------
+ 1 1 Product1 £150 1
+ 2 1 Product2 £50 1
---------------------------------------
2 Ringo £50
---------------------------------------
+ 3 2 Product3 £50
Is it possible (given tables 1 and 2) to create an HTML table similar to table 3? Where for each order underneath there are the orders corresponding order lines information
Thanks
It's not possible to make a single table with real* nested relationships in SQL. Each SQL table is nothing more than a big two dimensional grid, no exceptions.
The correct way to store this type of relationship is in multiple tables, as you already have done.
You haven't said why you are trying to do this, but it sounds like it is a requirement for display rather than for storage. If so, the answer is to have whatever is producing the display query multiple tables as appropriate to get the information you need. This might be a single SQL query with a join, or it might be multiple queries. That depends on having more information about what you are doing.
*Sometimes nested relationships can be modeled within the rigid structure of a single table, but that isn't appropriate in your case.

Create Excel Format Output using HTML and JavaScript

I had interview and question asked was:
Write a JS plugin that can take cell and value as input and render excel format output on browser. For example,
Given Input (cell and value):
J3 = 5
A2 = 20
K1 = 10
Output on browser should be in excel format
A B C ....... J K .......
1 10
2 20
3 5
..
I Was looking for correct solution for the problem.
I tried solving this problem (writing psudeo code)
var cell = {"J3": 5, "A2":20, "K1": 10}
// Function they will call for generate excel style table
generateExcel(cell, selector) {
1. create blank table which has A-Z column (with selector as A-Z resp) and 1 to 100 rows (with selector as 1 to 100 resp)
2. Loop through each cell and for each cell
2.1 find the column (J) and row (3)
2.2 Add/replace value in that TD
3. Once all the information from cell in enter in table, print the table in the document at given selector
}
They said it won't be efficient for huge number of cell inputs. I suggest that we can use Matrix create table
A B... J K ....
1 [ 10 ]
2 20
3 5
I think you started off well. Begin by creating a table that will contain the elements. This will be 26 columns wide and as tall as the largest y value. Convert the letters to numbers.
Sorry for w3schools link, I'm liable to get downvoted for even mentioning them, but they have the best laid out documentation on the table object that I could google for you. I will update it if someone has something better.
http://www.w3schools.com/jsref/dom_obj_table.asp
MDN Tutorial
https://developer.mozilla.org/en/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces
You can then access the table cell most efficiently through
var table = ;//get by id or create element, not sure what they expect
table.rows[y].cells[x].appendChild(...);
Excel spreadsheets are tables. Can you use a simple table? If so, I would recommend the CSS border-collapse property to make it look better, as well as perhaps reducing cell padding and margin.

Categories