Telerik RadPanelBar - Bind Parent Items using GROUP - telerik

I have a scenairo where I need to bind a RadPanelBar to a SQL table similar to the below structure:
ID, Name, Category
1, Fred, Male
2, Sam, Male
3, Fred, Male
4, Sam, Female
5, Louise, Female
6, Tom, Male
I need the panelbar to be in a Category > Name structure (i.e. each name to be a child item of their gender) but can't see an easy way to do this from Telerik's examples.
Any help/suggestions would be greatly appreciated.
Thanks in advance.

You should look at the Data Bindings example and the Hierarchical Data Binding example.
Each item in the RadPanelBar has an item id. For child items you have to define a parent id also. The problem is that the database table does not have root items (male, female) stored as rows, so you have to add them first before binding to a RadPanelBar.
You can read the database table into a list or dataset, like in the example, and add the missing root items there.
Or, if you are using declarative binding (in ASPX), you can use UNION statements in a SQL query:
SELECT
id
,CASE WHEN Category = 'Male' THEN -1 ELSE -2 END AS ParentID
,name
FROM table
UNION
SELECT
-1 AS id
NULL As ParentID
'Male' AS name
UNION
SELECT
-2 AS id
NULL As ParentID
'Female' AS name

Related

Oracle looping query to get value plus child values from same table

I have a table which contains values in a hierarchy structure.
I was wondering if anyone knew of a query where I could loop through each row finding it's ID and then search for rows with a PARENTID of the same value. So for example:
With a table
ID PARENTID LEVEL VALUE
-------------------------------
1 0 COUNTRY USA
2 1 CITY NYC
3 1 CITY LA
4 2 TEAM GIANTS
5 2 TEAM JETS
6 3 TEAM RAMS
7 3 TEAM CHARGERS
I could start by searching for ID:2 (NYC) and from there find all teams in that city. Something like (but I do not know the total loops I'll need to do)
SELECT ID2,VALUE FROM TABLE1 WHERE PARENTID = ID1;
Gives me:
3,LA
6,RAMS
7,CHARGERS
connect by is a common way to loop through a hierarchy like that. If you add start with, you can pick a starting point in the hierarchy.
SELECT table1.*, level
FROM table1
START WITH id = 3
CONNECT BY parentid = PRIOR id;
Please note that level is an Oracle keyword which will tell you how many loops you have stepped through so far. I wouldn't recommend using it as a column name. There's some other pseudocolumns and functions you might find helpful too.

How to fetch value of checkbox in oracle apex if I used a blank form?

I want to put the value of checked name from a checkbox in oracle apex into a table, but unable to do that.
I tried taking help from google but the steps mentioned didn't work too.
Could you please advise how to do that if I have taken a blank form and then added a checkbox to it, also I fetched the checkbox value from LOV.
As I understand, you are using a List of Values as a source of your checkboxes. Let's say you have following values there:
return value display value
----------------------------
123 andAND
456 Dibya
789 Anshul
321 aafirst
555 Anuj
When you select several values, APEX puts their return values into a string and separate them with :. So for the case in your screenshot the value in item P12_NEW will be 123:555. To split this values you can use the following query:
select regexp_substr(:P12_NEW, '[^:]+', 1, level) values
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
The result will be:
values
------
123
555
Next, you need to put these values into table usr_amt (let's say with columns user_id and amount, and the amount is entered into item P12_AMOUNT):
merge into usr_amt t
using (select regexp_substr(:P12_NEW, '[^:]+', 1, level) user_id
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
) n on (n.user_id = t.user_id)
when matched then update
set t.amount = :P12_AMOUNT
when not matched then insert (user_id, amount)
values (n.user_id, :P12_AMOUNT)
This query will search for the each user_id selected in the table, and if the user presents there, updates the corresponding value to the value of item :P12_AMOUNT, if not present - inserts a row with user_id and the value.

Oracle: How to find in a tree

Sorry for my English.
Is table Category:
ID
PID
name
And hierarchy:
Category 1
Category 2
Category 3
Category 4
Category 5
Category 3
Category 7
Category 8
Name of category may be repeated. How do I can to find all children on request: "Category 2 and Category 3" for oracle?
The result should be:
Category 2
Category 3
Category 4
Category 5
== Updated ==
I need to find by name "Category 2 AND Category 3", because name of category may be repeated!
A couple of assumptions. PID is the parent id of the current record and you know the ID of category 2.
I will use 245 as the id of category 2 in this example. If you don't have a way to get a unique id for the starting category, that is a different problem all together that has to be solved in your data.
(I gave a similar answer to another question yesterday doing a bottom up query. The difference between bottom up and top down is the order of the col1 = col2 in the connect by prior statement.)
Use a hierarchical query.
select Lpad(Name,Length(Name) + LEVEL * 10 - 10,'-') Name
from Category
start with id = 245
connect by prior id = pid;
Here is an sqlFiddle.
============Edit==============
Added this now that I'm more clear on what you need.
select Lpad(Name,Length(c1.Name) + LEVEL * 10 - 10,'-') Name
from Category c1
start with c1.name = 'Category 2'
and c1.id in (select c2.pid from category c2 where c2.name = 'Category 3')
connect by prior c1.id = c1.pid;
This will give you all branches starting with a Category 2 that have a Category 3 as the next child.
I've added another sqlFiddle with an additional branch having a 2 / 5 relation so you can see it only returns the two 2 /3 branches.

oracle connect by multiple parents

I am facing an issue using connect by.
I have a query through which I retrieve a few columns including these three:
ID
ParentID
ObjectID
Now for the same ID and parentID, there are multiple objects associated e.g.
ID ParentID ObjectID
1 0 112
1 0 113
2 0 111
2 0 112
3 1 111
4 1 112
I am trying to use connect by but I'm unable to get the result in a proper hierarchy. I need it the way it is showed below. Take an ID-parentID combo, display all rows with that ID-parentID and then all the children of this ID i.e. whose parentID=ID
ID ParentID ObjectID
1 0 112
1 0 113
3 1 111
4 1 112
2 0 111
2 0 112
select ID,parent_id, object_id from table start with parent_id=0
connect by prior id=parent_id order by id,parent_id
Above query is not resulting into proper hierarchy that i need.
Well, your problem appears to be that you are using a non-normalized table design. If a given ID always has the same ParentID, that relationship shouldn't be indicated separately in all these rows.
A better design would be to have a single table showing the parent child relationships, with ID as a primary key, and a second table showing the mappings of ID to ObjectID, where I presume both columns together would comprise the primary key. Then you would apply your hierarchical query against the first table, and join the results of that to the other table to get the relevant objects for each row.
You can emulate this with your current table structure ...
with parent_child as (select distinct id, parent_id from table),
tree as (select id, parent_id from parent_child
start with parent_id = 0
connect by prior id = parent_id )
select id, table.parent_id, table.object_id
from tree join table using (id)
Here's a script that runs. Not ideal but will work -
select * from (select distinct test.id,
parent_id,
object_id,
connect_by_root test.id root
from test
start with test.parent_id = 0
connect by prior test.id = parent_id)
order by root,id
First of all Thanks to all who tried helping me.
Finally i changed my approach as applying hierarchy CONNECT BY clause to inner queryw ith multiple joins was not working for me.
I took following approach
Get the hierarchical data from First table i.e. table with ID-ParentID. Select Query table1 using CONNECT BY. It will give the ID in proper sequence.
Join the retrieved List of ID.
Pass the above ID as comma seperated string in select query IN Clause to second table with ID-ObjectID.
select * from table2 where ID in (above Joined string of ID) order by
instr('above Joined string of ID',ID);
ORDER BY INSTR did the magic. It will give me the result ordered by the IN Clause data and IN Clause string is prepared using the hierarchical query. Hence it will obviously be in sequence.
Again Thanks all for the help!
Note: Above approach has one constraint : ID passed as comma separated string in IN Clause. IN Clause has a limit of characters inside it. I guess 1000 chars. Not sure.
But as i am sure on the data of First table that it will not be so much so as to cross limit of 1000 chars. Hence i chose above approach.

Select all rows from SQL based upon existence of multiple rows (sequence numbers)

Let's say I have table data similar to the following:
123456 John Doe 1 Green 2001
234567 Jane Doe 1 Yellow 2001
234567 Jane Doe 2 Red 2001
345678 Jim Doe 1 Red 2001
What I am attempting to do is only isolate the records for Jane Doe based upon the fact that she has more than one row in this table. (More that one sequence number)
I cannot isolate based upon ID, names, colors, years, etc...
The number 1 in the sequence tells me that is the first record and I need to be able to display that record, as well as the number 2 record -- The change record.
If the table is called users, and the fields called ID, fname, lname, seq_no, color, date. How would I write the code to select only records that have more than one row in this table? For Example:
I want the query to display this only based upon the existence of the multiple rows:
234567 Jane Doe 1 Yellow 2001
234567 Jane Doe 2 Red 2001
In PL/SQL
First, to find the IDs for records with multiple rows you would use:
SELECT ID FROM table GROUP BY ID HAVING COUNT(*) > 1
So you could get all the records for all those people with
SELECT * FROM table WHERE ID IN (SELECT ID FROM table GROUP BY ID HAVING COUNT(*) > 1)
If you know that the second sequence ID will always be "2" and that the "2" record will never be deleted, you might find something like:
SELECT * FROM table WHERE ID IN (SELECT ID FROM table WHERE SequenceID = 2)
to be faster, but you better be sure the requirements are guaranteed to be met in your database (and you would want a compound index on (SequenceID, ID)).
Try something like the following. It's a single tablescan, as opposed to 2 like the others.
SELECT * FROM (
SELECT t1.*, COUNT(name) OVER (PARTITION BY name) mycount FROM TABLE t1
)
WHERE mycount >1;
INNER JOIN
JOIN:
SELECT u1.ID, u1.fname, u1.lname, u1.seq_no, u1.color, u1.date
FROM users u1 JOIN users u2 ON (u1.ID = u2.ID and u2.seq_no = 2)
WHERE:
SELECT u1.ID, u1.fname, u1.lname, u1.seq_no, u1.color, u1.date
FROM users u1, thetable u2
WHERE
u1.ID = u2.ID AND
u2.seq_no = 2
Check out the HAVING clause for a summary query. You can specify stuff like
HAVING COUNT(*) >= 2
and so forth.

Resources