Using Select2 on APEX tabular forms

I love the Select2 jQuery plugin. It’s a feature rich, good looking, select list replacement. As an APEX developer, it makes sense to use the excellent plugin from Nick Buytaert. Since its announcement, in Aug 2013, you would be hard pressed to find an APEX application where I don’t use it.

All that said, APEX doesn’t (yet) support plugins on tabular forms. This blog post is about documenting the JavaScript and Dynamic Actions (DA) you could use to use it as part of a tabular form.

The Quick and Easy Approach

If your tabular form contains a Select List already, this method is for you. It will work whether you used a Column Type of “Select List” or APEX_ITEM in it’s various forms: apex_item.select_list , apex_item.select_list_from_query or apex_item.select_list_from_query_xl.

  1. You include the Select2 library on the page. (more on this in a moment)
  2. You target your Select Lists with jQuery and run the .select2() method on them. Yup, that’s it.

Step #2 may look like this:

or if you have any options to include:

Check out this demo. (Click on the “Apply Select2” button).

The button runs a simple DA that runs the code above. Notice that, if you’re using the Universal Theme in APEX5 you may want to remove the select list styling applied by the class “u-TF-item–select”. Use a command like this:

Let’s talk about #2 above. In order to include the Select2 library on the page, I like to “cheat” whenever possible and have at least one Select2 APEX item plugin on the page. Doing this will include all the JavaScript and CSS that you need to run the .select2() method. That’s exactly how the previous demo page works.

The (slightly) Messy Approach

However, if it’s not possible or desirable to include a regular Select2 item on your page, you’ll have to manually add the necessary libraries. This can get a little tricky if say for example you download the Select2 jQuery files, they don’t match the version used by the plugin, and then later you add a Select2 item plugin to the page.  You’ll want to be careful with that.  For this reason, I like to use the same files that the Select2 item plugin is using. That’s also not ideal because you could upgrade the plugin and then again be in conflict with the versions. My preferred approach is to move the file includes of the Select2 APEX plugin to their own procedure. Share that new procedure between the Select2 APEX plugin and my own, simple, “Manual Select2” plugin. You always move all plugin code to a package don’t you? (perhaps that’s a conversation for a different blog post).
This new “Manual Select2” plugin is what we’ll use to initialize the select lists on a tabular form.

My new procedure with the includes looks like this:

The original Select2 plugin changes to something like this:

For the new plugin, we’ll use a Dynamic Action type plugin with an Initialize category. It will have only one custom attribute for the component. The attribute will be used to contain the code that will initialize the select2 items.

Select2 Manual Plugin

When we use the plugin, the code “JS Function” can look like this:

Or it can be a lot more complicated, for example:

As you can probably tell from this code, you’re not limited to using this on tabular forms. With this technique you can use the full power of the Select2 plugin, like for example using the formatResult or formatSelection options that allow you to specify a function that formats how the values are displayed.

This technique does require some trial an error, but hopefully it gives you a starting point to extend the capabilities of your applications.

Check out the demo using the Manual Select2 plugin approach.
Here’s the plugin dynamic_action_plugin_com_enkitec_manual_select2.sql.

The code code of the Manual Select2 plugin looks like this:

It basically takes the code you provide (the code to initialize select2), wraps it with a function and calls it on page load.

If you provide the code:

The function will look something like this (additional formatting added for clarity):


UPDATE Feb 7, 2016: I’ve added a new fully working example implementing Lazy Loading.

UPDATE Oct 7, 2016: Github Repo with the App


Hi, I'm Jorge Rimblas. Father, husband, photographer, Oraclenerd, Oracle APEX expert, Oracle ACE, coffee lover, car guy, gadget addict, etc... I'm a Senior APEX Consultant with Insum Solutions, a consulting firm specialized in Oracle databases and the APEX development tool. I have worked with Oracle since 1995 and done eBusiness Suite implementations and customizations. Nowadays I specialize almost exclusively in Oracle APEX.

34 comments on “Using Select2 on APEX tabular forms
  1. Tony Miller says:

    Wonderful article.. Now I have a question, involving manual tabular forms and the select2 plugin. In your demo you are showing select lists only. Do you have an example of an autocomplete textbox in a tabular form?

    • Ah great question, I do not, but I did implement the AJAX (lazy loading) option in the tabular form. It looked something like this.

      This is how the dcDic referenced above is populated

      Now, for a future blog post, I did implement a tabular form autocomplete using awesomplete
      That little plugin really rocks!

  2. Tony Miller says:

    Sorry fat fingered last posting… I have have an issue with a manual tabular form needing a couple of autocomplete textboxes and am stuck.. Posted up on the APEX support Forum:

  3. Tony Miller says:

    Appreciate the help on this issue. I have changed the password on the demo account since it seems someone else was accessing the account and running pages and such.

    I also have to try and take the application from that instance and move back to my office instance, a mistake occurred and they wiped out the application and tables. They are looking to a backup but are worried it might be too much of a pain to restore for schema..

  4. sawalhah says:

    Great post.
    could you please export the plugin from your application as a sql file.

  5. Satheesh Kumar says:

    Good article.
    I tried the plugin it is working for already loaded rows, but when i tried to click add row button , plugin is not working.

    • When the new row is added, the corresponding elements need to be initialized via the select2() call. When the Add Row button is called it calls apex.widget.tabular.addRow();. Unfortunately, the call doesn’t issue any JS events. If it did, it would be easier to know when to initialize the selects. One way around this, might be changing the button to call your own function: onclick=”addRow()”

      function addRow() {
      $("#reportID").find(".t-Report-report tr:last").find("select[name='f01']").select2();

  6. Heinz says:


    The download link is down….

  7. Hi Jorge,
    I have been using Select2 in Tabular forms too albeit an equally messy manual approach and have been meaning to package up as a plugin for a while – but as you mentioned, creating an easy to use plug-in for Tabular forms isn’t the most straight forward. I did a presentation on adding it manually at the Apex Meetup in Leeds.
    I see that you have added the Lazy loading segment – to allow for the select list to be loaded when clicked – correct me if I’m wrong?
    Assuming I haven’t misunderstood, I have a different solution to this – and happy to share my code if you are interested. My solution essentially loaded the entire results set of the select list into a JSON array in a page load event.
    It then appends the results of the stored JSON onto the select2 elements.
    This essentially means that you only need 1 database call to populate all of the Select2s – and by storing the JSON values in a JavaScript array – it can be called again and again at any point – for example after a region refresh DA.
    This was particularly useful when I wanted to apply Select2 to a Select list which had thousands of results.
    Let me know, if this sounds useful to you – and I would be happy to share my code.
    Many thanks,

    • Adrian, I really like the sound of the solution you describe storing the values in JSON and it makes a lot of sense. User experience is probably pretty nice too. I basically follow a similar technique when loading the form for existing data. It would be pretty nice to do something similar for the regular functionality.
      Yeah, please share the code, here or via email (first at last dot com)

      Thank you

  8. Cj says:


    Thanks for an excellent post.

    Your solution works really well, but I have noticed that if a report is reloaded using PPR, (for example when navigating to the next page in the report pagination), that the Select2’s are not being generated.

    To get around this, I have changed the following:
    l_result.javascript_function := ‘NULL’;
    l_result.javascript_function := ‘function() { ‘|| l_func_prefix|||| ‘(); }’;

    and then moved that line down to the bottom of the ‘IF’ statement. This allows the Select2’s to be re-generated when the report is refreshed.

    On a side note, I am currently working on a solution, based around your work, and that of Nick Buytaert to create this solution in a complete plugin, without the need to create a PL/SQL dynamic region or Application Process, and based the whole data source on an LOV in APEX.

    I’ll let you know how I get on!



  9. Thanks…This plugin is very helpful for tabular form ..However only the clear icon is not coming ..
    var options={allowClear: true, width: “150px”};

    Can you please help me out.

  10. Kumar says:

    Hey Jorge, Can you please provide video of this functionality or any sample app i can look in backend how its coded.

  11. Panagiotis Katsoulis says:

    Hi again,
    select2 (change etc..) events work in the tabular form?
    In my case only default change event works but on a new row (addrow) it doesn’t trigger at all.

  12. Mario Ruiz Diaz says:

    Hi there! Im new on this and I really want to make this work, I want to know if this works in Master detail Pages, Im trying to do it but I cant, can you give me a hand? I think that the problem is that I have more than one Select2 in my page, cause they have change their form but my tabular dont, hope you understand my problem! Thanks!

  13. Drew D says:

    Will this work on a tabular form with apex 4.2 or just 5+. I need a users to select one or more values from a select list in a tabular form.

  14. Drew D says:

    I have downloaded and installed the 4.2 version, but “Select2” is not an option when I try to edit the column attribute. Do you have instructions on setting it up/overriding/forcing Apex to use the Select2 plug-in with a tabular column form item? Any example or demo app?

  15. Drew D says:

    Sorry, the post is just not that easy to follow, with bits and pieces in the comments. I’m not sure why your example uses a button to apply select2. Do we have to use a button, or can we just put the code in the header? And the comments suggest you have to do other coding for it to work correctly after clicking Add Rows. You also say you like to “cheat’ by have the select2 list used elsewhere on the same page. Would you put it in it’s own region, then hide the region or have it return no records so it doesn’t display anything?

    • The button is for demo purposes. On a real app you want to use a Page Load Dynamic Action, just like p20 and p30 do on my demo (did you see those?).
      Yes, you do need to handle the Add Rows and call .select2() on those. Otherwise the new row will have a regular select list. You need to instantiate the Select2 element on the new row.
      Hope this helps!

  16. ibrahim says:


    It is really great post, this post helped me a lot for one of my requirement.

    But I have one issue when I use this select2 plugin i.e.

    I have created a manual tabular from and Using Select2 on APEX tabular forms I have applied select2 options on one of the tabular form column “DNAME”.

    On click ‘Add Row’ button a new row appended to tabular form, after filling the data in new rows when I click save/submit newly appended records columns values are stored in the table as I filled but DNAME column values stored as null.

    When I do inspect element,

    Whenever a new row gets appended in the form the select2 plugin is appending the div’s based on the count of the rows which is not allowing us to submit the data.

    When I added one row the div is appending perfectly.

    But when I add another row in the tabular form more than 1 divs are getting appended which is causing problem for the data to be submitted which can be seen in below figures:

    I have produced same issue in test environment below are the credentials for work space/application access.

    Please check and help me to overcome this issue.
    Workspace: globle_app
    Password : Demo

    Thanks and regards,
    Ibrahim Sayyed.

  17. Tom says:

    I have loaded your app in Oracle workspace. On page 20 of your application, what would I change to make the tabular form select list a multi-select field ? Would I change the dynamic action option field and add multiple:true ?

  18. Tom says:


    Do you have an example of saving a mult-select value out of an Apex Tabular Form value using the Automated Row Processing using Select2 plugin ? Or is this possible ? Works fine for single select values but when adding “multi-selected” values I have a problem. Any help appreciated.

I love comments, write me a line