Feb 09

Fancybox in APEX dynamic report

Print Friendly

This post has 493 words. It will take approximately 4 minutes, 55 secondes for reading it.

Using fancybox in Oracle Application Express (APEX) can increase the page load performance specially when You have lot of items in one page and user needs to scroll down to reach the bottom which is quite annoying for some users. You can split your long page scrolling content into few pages and use link to open these additional information on demand using fancy box. So you are not leaving the main page but you can still access additional resources if you want to. It is working so good so far for me. Read my previous article if you do not know how to implement fancybox in APEX.

Now when it comes to the point where I wanted to implement fancybox in APEX dynamic report. Basically what I am trying to do in my report is – provide URL link for relevant image and display the image in fancybox when user click on it.

It works good when I load the page and rendered the report with the following code -

<script type="text/javascript">

$(document).ready(function(){
          $("a.fancyImg").fancybox({
                                   'transitionIn'	: 200,
                                    'transitionOut'	: 200
                                   });
                          });
</script>

The fancybox functionality breaks when partial post back happened into the page. So when I want to do column sorting or perform any other action in dynamic report fancybox link does not work. I understand that because my function only called once on document ready and it does not work for partial page load. Here is the screen capture of my report.

I have used custom SQL report query for URL link column. Here is the sample if you want to know how -

SELECT F.FAC_ID,
       F.FAC_TYPE,
       F.LOCATION,
       F.FAC_ASSET_DESC "Description",
       F.FAC_ASSET_NO "Asset No",
       F.FAC_ASSET_CONDITION "Condition",
       F.FAC_REPLACEMENT_COST "Initial Cost",
       F.REPLACEMENT_COST_TODAY "Todays Cost",
       F.FAC_LATITUDE_DEC "Latitude",
       F.FAC_LONGITUDE_DEC "Longitude",
       CASE
          WHEN fil.fil_id IS NOT NULL
          THEN
                '<a class="fancyImg" href="f?p=&APP_ID.:44:&SESSION.:::44:P44_FIL_ID:'
             ¦¦ fil_id
             ¦¦ '">View Image</a>'
          ELSE
             'No image'
       END
          Image
  FROM FACILITIES F, BUILDINGS B, FILES FIL
 WHERE     F.FAC_ID = B.FAC_ID(+)
       AND F.FAC_TYPE = 'BUILDING'
       AND FIL.SOURCE_ID(+) = F.FAC_ID

Now I have changed my javascript to use without document ready function. Here is the code -

<script type="text/javascript">

function fancyGallery(){
$("a.fancyImg").fancybox({
   'transitionIn'		: 200,
   'transitionOut'		: 200
});
}
</script>

Call this function in the report dynamically in onClick event.

CASE
          WHEN fil.fil_id IS NOT NULL
          THEN
                '<a class="fancyImg" onClick="javascript:fancyGallery();" href="f?p=&APP_ID.:44:&SESSION.:::44:P44_FIL_ID:'
             ¦¦ fil_id
             ¦¦ '">View Image</a>'
          ELSE
             'No image'
       END
          Image

It works fine in IE but I am not sure about FireFox.

 

 

Feb 01

Implementing fancybox in oracle APEX application

Print Friendly

This post has 211 words. It will take approximately 2 minutes, 6 secondes for reading it.

Recently in one of my application I have implemented Fancybox to give better user experience. I guess this is quite useful when you have too many items in one page and user has to scroll down to view details in the page. This will give better user experience hiding extra stuff from the page and make it available on demand or request.

I wanted to implement this functionality because in my relational database I have a master table which holds most of the common fields and I have created some child tables for store extra information for different types of assets e.g. furniture, building, structure etc. Instead of sending user to different page to enter additional information, I wanted to give a bit flexibility so that user will be in the same page and they can enter details of specific asset information in fancy popup window if they want to. It will also give a bit better experience in terms of page load as it will load only necessary fields. The page looks like this -

First of all, you have to download the script from http://fancybox.net and Once you downloaded zip file, extract it where ever the location you like.

Read the rest of this entry »

Jan 24

Hide checkbox group in APEX using jQuery

Print Friendly

This post has 611 words. It will take approximately 6 minutes, 6 secondes for reading it.

In Oracle APEX I wanted to show and hide a check box group depending on the value of another text-field. I guess it is quite handy when you want to hide irrelevant fields from the page and when you have too many fields to avoid scrolling. This feature may also give good user experience. I am assuming you already have some knowledge about jQuery and know a little of it. For details please visit http://jquery.com

To do this I have used jQuery and did a bit hack in APEX html code. In this scenario, I have Revised Cost field and Reason for revision check boxes. Now I do not want to display the check boxes unless Revised Cost field is not empty and when user click on that field to enter data. Here is the screen capture of my page -

APEX Page

Important!

Print Friendly

This post has 22 words. It will take approximately 13 secondes for reading it.

I am actually using APEX 3.2 for this exercise. I am sure you could do it much more easier way in APEX 4.x.

Once the page is rendered, view the source code of the page. You can right click on the middle of screen and click on view source in Internet Explorer. In FireFox just right click on the middle of the page then click on view page source.

Now I am looking for the relevant html code for these fields. The code will look like this -

<input type="text" name="p_t29" size="12" maxlength="2000" id="P3_FAC_REVISED_COST"
        value="332" />
    <div id="content">
    </div>
    <label for="P3_REASON_COST_REVISED">
        <a style="text-decoration: none; font-weight: bold;" href="javascript:popupFieldHelp('23893628613382143','198940878990662')"
            tabindex="999">Reason for revision:</a></label>
    <fieldset id="P3_REASON_COST_REVISED" class="checkbox_group">
        <input type="checkbox" name="p_v31" value="INITIAL_UNKNOWN" id="P3_REASON_COST_REVISED_0" /><label
            for="P3_REASON_COST_REVISED_0">Initial cost is unknown</label><br />
        <input type="checkbox" name="p_v31" value="DIFFERENT_DESIGN" id="P3_REASON_COST_REVISED_1" /><label
            for="P3_REASON_COST_REVISED_1">New asset will have different design or materials</label><br />
        <input type="checkbox" name="p_v31" value="TODAYS_INACCURATE" id="P3_REASON_COST_REVISED_2" /><label
            for="P3_REASON_COST_REVISED_2">Today's cost was inaccurate</label><br />
    </fieldset>

 

Now examine the above code, all the check boxes are inside the fieldset. I can actually hide the whole field set instead of individual check boxes. You can hide individual check boxes if you want. I also have to hide the relevant label to hide/show based on the value of the text field.

Place the following javascript in the header section or footer section of the page -

<script type="text/javascript">
$(document).ready(function () {

        // get the text field value
        var pr = $('#P3_FAC_REVISED_COST').val();

        if (pr.length === 0) {
            //hide the label if above condition matches
            $("label[for=P3_REASON_COST_REVISED],#P3_REASON_COST_REVISED").hide();
            //hide the text field if above condition matches
            $('#P3_REASON_COST_REVISED').hide();
        }

        $('#P3_FAC_REVISED_COST').click(function () {

            //for new entry I want to show the fields if user click on the text field

            $("label[for=P3_REASON_COST_REVISED],#P3_REASON_COST_REVISED").show();
            $('#P3_REASON_COST_REVISED').show();

        });

    });

</script>

 

The page in action now -

 

But when the field has some values, it does not hide any more -

Jan 17

Counting record and sorting with fiscal month in APEX chart

Print Friendly

This post has 643 words. It will take approximately 6 minutes, 25 secondes for reading it.

Recently in one of my project that built in Oracle APEX. This is basically a Change Request System (CRS) built in APEX to submit or log any change request by system users for other corporate systems. It was working quite well with the notification and reporting. When user submit a new request I get an email notification and then I access to the CRS to review and action the request. User who originally posted the request get notified every time I do changes in the request log and get update about the progress of the request.

I thought it will be good to have some sort of summary report with chart to see how many calls logged each month and how much change we do in the system. Started to create a new page with chart and scripted my simple query in TOAD first to make sure the script written correctly. Here is my initial script to implement chart -

-- To count records for each month
SELECT NULL Link, TO_CHAR (create_date, 'MON/YY') AS "Month", COUNT (*) AS "No of records"
    FROM RT_RFC
GROUP BY TO_CHAR (create_date, 'MON/YY')
ORDER BY TO_CHAR (create_date, 'MON/YY')

The query works well in TOAD and I have carried over the script to my APEX page. Here is what I get output from my chart.

APEX Flash Chart

Ops! I did not realize that the chart was not rendering months according to fiscal year instead it was rendering alphanumerically. Actually it was doing the same in TOAD but I did not notice in first instance. This is not going to help and I can see why it was sorting alphanumerically because I was converting date to char (string) :( .

I have tried different approach using trunc() and it works fine APEX standard report however I had set the column format to month in the report column heading to ‘Month’ . Here is the truncate statement -

 SELECT NULL link, TRUNC (create_date, 'MONTH') AS "Month", COUNT (*)
    FROM rtt_rfc
GROUP BY TRUNC (create_date, 'MONTH')

When I have implemented this code in Chat control it was displaying ’1-MAY-2010′ which is what I do not want to display like. I want to display only Month name. Here is what I got with this script -

Flash Chart in APEX

As you can see I have change the rotation to display the month in 45 degree rotation but unfortunately I could not find any way to format the month field to display only month. I had to think for alternate solution.

Ok, I suddenly thought how about if I use case statement to achieve this. Here is what I have done -

SELECT NULL link,
         CASE
            WHEN TO_CHAR (create_date, 'MM') = 1 THEN 'JAN'
            WHEN TO_CHAR (create_date, 'MM') = 2 THEN 'FEB'
            WHEN TO_CHAR (create_date, 'MM') = 3 THEN 'MAR'
            WHEN TO_CHAR (create_date, 'MM') = 4 THEN 'APR'
            WHEN TO_CHAR (create_date, 'MM') = 5 THEN 'MAY'
            WHEN TO_CHAR (create_date, 'MM') = 6 THEN 'JUN'
            WHEN TO_CHAR (create_date, 'MM') = 7 THEN 'JUL'
            WHEN TO_CHAR (create_date, 'MM') = 8 THEN 'AUG'
            WHEN TO_CHAR (create_date, 'MM') = 9 THEN 'SEP'
            WHEN TO_CHAR (create_date, 'MM') = 10 THEN 'OCT'
            WHEN TO_CHAR (create_date, 'MM') = 11 THEN 'NOV'
            WHEN TO_CHAR (create_date, 'MM') = 12 THEN 'DEC'
         END
            "MONTH",
         COUNT (*) AS "No of Request"
    FROM rtt_rfc
GROUP BY TO_CHAR (create_date, 'MM')
ORDER BY TO_CHAR (create_date, 'MM')

Hmm, it is looking good in TOAD when ran the query and doing exactly what I wanted to do. Now I took the query into the chart report. Here is what I got -

 

Wow! it is working perfect now. Hope this will help someone to play around with date field.

 

Jan 12

Implementing AJAX keyword search from database table

Print Friendly

This post has 698 words. It will take approximately 6 minutes, 58 secondes for reading it.

In this exercise, I will demonstrate how to implement a simple keyword search in MS SQL Server database using textbox and gridview control in Asp.NET AJAX technology. Most of the websites now use AJAX technology to avoid the full postback and better user experience. It is wonderful, personally I love it. To begin with this exercise I assume you have a SQL Express or SQL Server database installed. I will use global connection string from web.config file. The connection string in my web config file pointing the SQL Express database located in App_Data folder. Here is the connection string -

<connectionStrings>
  <!--Your connection string for database-->
  <add name="myConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=¦DataDirectory¦\practice.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>   

</connectionStrings>

Now, in the default.aspx page. I have created a textbox control and a submit button to trigger the query when something entered in the input textbox. I also have created a simple validation control and validation summary control to force user to type anything in the textbox before submitting the page on button click. I also have created a gridview control to display the query data. In this exercise I have not selected any specific column in the gridview control so that  it will display all columns from the source table.Here is what I have done -

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>     

<div>         

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p>Enter employee last name and click on submit button to search. You can enter a few letters of the employee last name to search.</p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
Last Name: <asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="You must enter a name."             ControlToValidate="txtName">*</asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />             

<p>Display result here.</p>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</ContentTemplate>         

</asp:UpdatePanel>         

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
        <ProgressTemplate>
                <img src="loading.gif" />
        </ProgressTemplate>
</asp:UpdateProgress>         

</div>          

<asp:SqlDataSource ID="dsEmployee" runat="server" ConnectionString="<%$ ConnectionStrings:myConnection %>"
SelectCommand="SELECT * FROM emp WHERE (lastName like @LastName+'%')">
    <SelectParameters>
        <asp:ControlParameter Name="LastName" ControlID="txtName" type="String" />
    </SelectParameters>
</asp:SqlDataSource>

 

 

Important!

Print Friendly

This post has 17 words. It will take approximately 10 secondes for reading it.

Note, inside update progress template I am using an image to display while fetching the gridview result.

Now I have to create an event for submit button. I have created an event handler for submit button so that it will be triggered when button is clicked by user. It is very simple event here, I have indicated the datasource for Gridview control and then bind data. When button is clicked, dataSourceID gets select parameter value from the textbox control and refine the search accordingly.

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click         

	'selecting the datasource for gridview1 on button click event
	GridView1.DataSource = dsEmployee
	'Bind data to gridview
	GridView1.DataBind()
End Sub

 

I have saved the page, and right click on the default.aspx page, click on view in browser. Here you got a simple ajax keyword search engine. Type a latter of a name  and click on submit button it will display all the records starting the last name with that letter.

You can also bind the the specific column/s to the gridview if you do not want to display all records from the table. Make sure you have set the AutoGenerateColumns to false  in Gridview like below -

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="empId">             

    <Columns>
        <asp:BoundField DataField="FirstName" HeaderText="First Name" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
    </Columns>
</asp:GridView>

 

 

 

Page 1 of 512345