CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [How To] Editable grid field select with filtering based on data column value

Print topic Send  topic

Author Message
rew-NZ

Posts: 21
Posted: 05/28/2008, 7:13 PM

Hi,
Basic Problem:
I have been trying to work out how to create a select field in an editable grid row that has different option values based on the row it is in.

What it is for:
I have a table of sub assemblies that is displayed on the page in an editable grid but sub assemblies can be nested and so a subassembly has an optional field to indicate it's parent sub assembly. The problem is a sub assembly can't be made up of itself, if it's part number is 1234 then it can't have a parent sub assembly with part number 1234.

What I am trying to do:
I want to display a drop down list in each row that gives the available sub assembly part numbers but doesn't include the part number of the row it is displayed in.

My impression so far:
It seems to me that the select is generated once and copied into each row field so I can't filter the select values with the where clause on the data source for the control with the row value.
I suspect I need to do something similar to an autofill or dependant list that is triggered by the onload even for the row 'part code' control, which in this case is a text box. The only problem is that because it is a text box the normal builders don't work. I had tried to see if I could fool a feature builder into going through it's process and then I could hack the generated code to do an innerHTML replacement to overwrite the generated field select but I didn't have much joy.

Any suggestions would be greatly appreciated.

Andrew
View profile  Send private message
mentecky

Posts: 321
Posted: 05/29/2008, 12:54 AM

Well... first, outstanding description of your problem!

You had me stumped on this one so I decided to prototype it out a bit. I created a table with "part_num", "parent_part_num" and an incremental ID. I added the following data to it:

  
part_id         part_num                 parent_part_num  
1                   1234                         0  
2                   SUB 1                      1234  
3                   SUB 2                      1234  
4                   2345                         0  
5                   NEW SUB 1            2345  
6                   NEW SUB 2            2345  

So... basically SUB 1 and SUB 2 are sub-assemblies of 1234. NEW SUB 1 and NEW SUB 2 are sub-assemblies of 2345.

In your editable grid set your listbox Data Source Type to "ListOfValues". Click the entire grid and in events "Before Show Row" click "Custom Code".

This is what I put in my event handler:
   $db = new clsDBmentecky();  
   $SQL = "SELECT * FROM parts WHERE parent_part_num = ".$parts->ds->ToSQL($parts->ds->f('part_num'), ccsText);  
   $db->query($SQL);  
   $Result = $db->next_record();  
  
   $options = "";  
  
   while ($Result)   
   {  
      // Add a Value, Text pair  
      $options[] = array($db->f('part_num'), $db->f('part_num'));  
      $Result = $db->next_record();  
   }  
  
   $db->close();  
  
   $parts->subassembly->Values = $options;  

$parts is my editable grid.
$parts->subassembly is my listbox.

You can see my prototype at http://www.mentecky.com/demo/parts.php

It's not fancy but I wanted to test out my listbox code.

Hope that helps!

Rick
_________________
http://www.ccselite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 4:36 AM

Quick short answer:
Not prototyped but:
In the SQL constructing the Grid row, you could create a field that holds the complete html for the listbox and its values obtained through a subselect.
This assumes that the listboxes are not comprised of thousands of rows.

If you like the idea, an experiment would be next.
Or, have you tried dependant listboxes? either CCS or CCT.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
rew-NZ

Posts: 21
Posted: 05/29/2008, 4:44 AM

Hi Rick,
Great work on the prototyping, I had a look at your demo and looking at the code was very helpful to see how to connect the data in to the select. I will have a play with it tonight to see if I can adjust it a bit but based on what you have shown me I can definitely get it doing it.

Here is a bit more info:
This was bang on as far as rough table structure but the select list functionality I am looking for is slightly different but close.

part_id part_num parent_part_num
1 1234 Null
2 SUB 1 1234
3 SUB 2 1234
4 2345 Null
5 NEW SUB 1 2345
6 NEW SUB 2 2345

All sub assemblies could have a parent part number of any one of the other sub assemblies.

The point of the drop down list:
Each grid row displays the full sub assembly details to either edit/add/delete that row and the drop down list is used to set the parent assembly part number. The example you put together well displayed the child part numbers but what I need is the drop down list to display every part number except the current row.

Side note:
The available list of sub assembly part numbers is limited to a job by job basis, the sub assembly part numbers for other jobs are not available outside there own job so the list is not too big.

Solution:
Easy to do in your code by changing the where to:

.... WHERE part_num <> '".$parts->ds->ToSQL($parts->ds->f('part_num'), ccsText)."' AND JobId = ".CCGetFromGet("jobId");

JobId is a URL param used in all page tabs to limit the returned components, sub assemblies and tasks by the job they are linked to. It is basically part of a drill down process to access more and more detail as required.

Thanks for the help I have only just started working with CodeCharge PHP over the last month so I am still coming to terms with the methodology, internal functions and the how, when and where to do things. Great help thanks for your time.
View profile  Send private message
rew-NZ

Posts: 21
Posted: 05/29/2008, 5:07 AM

Sorry bad format on the table getting used to the posting format too :-)

  
Reworked to match my setup  
part_id		part_num	parent_part_num		JobId  
1		1234		NULL			1  
2		SUB 1		1234			1  
3		SUB 2		SUB 1			1  
4		2345		NULL			2  
5		SUB 1		2345			2  
6		SUB 2		SUB 2			2  

Expected selects from this data viewing Job 1:

  
<row_1>  
<select id="part_1234_possible_parents" >  
   <option value="2">SUB 1</option>  
   <option value="3">SUB 2</option>  
</select>  
</row_1>  
  
<row_2>  
<select id="part_SUB 1_possible_parents" >  
   <option value="1">1234</option>  
   <option value="3">SUB 2</option>  
</select>  
</row_2>  
  
<row_3>  
<select id="part_SUB 2_possible_parents" >  
   <option value="1">1234</option>  
   <option value="2">SUB 1</option>  
</select>  
</row_3>  
View profile  Send private message
mentecky

Posts: 321
Posted: 05/29/2008, 5:11 AM

rew-NZ,
Thanks.

You may want to play with this function then if you have recursive assemblies:

Quote :
function getCategoriesList($link_category_id="0", $prefix="")
{
$values = "";

$db = new clsDBcommunity();

// Get counts for all sub categories
$SQL = "SELECT * FROM link_categories WHERE link_category_parent=$link_category_id ORDER BY link_category";

$db->query($SQL);

$result = $db->next_record();

while ($result)
{
$subvals = "";

// Add this category
$link_cat_id = $db->f("link_category_id");
$link_category = $db->f("link_category");

$values[] = array($link_cat_id, $prefix.$link_category);

$subvals = getCategoriesList($link_cat_id, $prefix.$link_category." - ");

for ($i=0; $i < count($subvals); $i++)
{
if (!empty($subvals[$i]))
{
$values[] = $subvals[$i];
}
}

$result = $db->next_record();
}

return $values;
}

I use it for data tables I build with the Catalog and Gallery builder. You will have to bend it for your use, but it basically builds a list for a listbox that will recursivelly build a dropdown on as many levels of "Parent ID" as you have.

Just a thought,

Rick
_________________
http://www.ccselite.com
View profile  Send private message
rew-NZ

Posts: 21
Posted: 05/29/2008, 5:28 AM

Hi Walter,
I thought about doing something similar to the linked list but the the dependent list is linked to a text box containing the part code not another list and I didn't have enough info as how to code that in CodeCharge by hand without a lot of buggering around at this point which I don't have the time to do.

I would be interested in any thoughts you had on that approach but only if you don't have anything better to do with you time :-)

I will use a modified version of Ricks prototype to get it done in the prototype application.

the whole select could be to a stored procedure that could dynamically create the select code required based on the table content and filtering rules as one of the returned field values. Definitely doable but the question I would have is how to inject the code into the innerHTML value of the cell and then make that available to the back end application as the other fields in the row. A dummy select might be the way to go but the id and other application requirements would also have to be sent to the procedure to retain the application accessibility to the control in the server code.

hmmm might be a bit complicated for me at this point I think.
Cheers for the input, I will continue to consider that detail could be helpful somewhere else.

Andrew
View profile  Send private message
rew-NZ

Posts: 21
Posted: 05/29/2008, 5:34 AM

Thanks Rick,
Will have a look over it tomorrow, ops or should I say today hmm 12:30am already how time flies when you are having fun. Trust me to organize a meeting for first thing in the morning, at least I will be able to tell them this is in the process of being resolved.
Cheers,

Rew
View profile  Send private message
mentecky

Posts: 321
Posted: 05/29/2008, 5:37 AM

No problem... BTW That function will give you all sub-assemblies from a base parent ID... so I really think it's a good fit for what you need. Let me know how it works out for you!

Rick

_________________
http://www.ccselite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 5:43 AM

@Andrew,
For now, if Ricks's solution get's the job done, go for it.
It is a good solution, I think.

As to the dependant listbox, it would need some tweak and twisting, but indeed I do not (at this moment) have the time.
Wishing you a good meeting, go rest.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
rew-NZ

Posts: 21
Posted: 05/29/2008, 6:59 PM

Hi All,

Here was the resulting code that worked a charm:

  
function vwjobsubassemblies_BeforeShowRow(& $sender)  
{  
    $vwjobsubassemblies_BeforeShowRow = true;  
    $Component = & $sender;  
    $Container = & CCGetParentContainer($sender);  
    global $vwjobsubassemblies; //Compatibility  
  
//Custom Code @841-2A29BDB7  
// -------------------------  
   $DBConnection = new clsDBConnection1();    
   //query that gets all the current job sub assembly part numbers but excludes the current row part number  
   $SQL = "SELECT * FROM JobSubassembly WHERE PartCode <> ".$vwjobsubassemblies->DataSource->ToSQL($vwjobsubassemblies->DataSource->f('PartCode'), ccsText)." AND JobId = ".CCGetFromGet("JobId");    
   $DBConnection->query($SQL);    
   $Result = $DBConnection->next_record();    
    
   $options = array();    
    
   while ($Result)     
   {    
      // Add a Value, Text pair    
      $options[] = array($DBConnection->f('PartCode'), $DBConnection->f('PartCode'));    
      $Result = $DBConnection->next_record();    
   }    
    
   $DBConnection->close();    
    
   $vwjobsubassemblies->HeadSubPartCode->Values = $options;    
// -------------------------  
//End Custom Code  
  
    return $vwjobsubassemblies_BeforeShowRow;  
}  

Thanks guys it did the trick, now on to the next problem.

Rew
View profile  Send private message
mentecky

Posts: 321
Posted: 05/29/2008, 11:19 PM

Rew,

Glad we could help!

Good luck with your project.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/30/2008, 2:06 AM

Pls change title to [Resolved] or [HowTo]

Good Job!
We will wait next challenge as we do not support problems, lol

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.