Thursday, November 28, 2013
On my quest to create a perfect PageBlockTable, I tried a lot of jQuery plugin available out there. The main moto was to bring as many as feature I can. Some of them were good but were almost dead and were at end of their lifetime. Others were not compatible with Visualforce, some were not able to pick the standard pageblock table and other had css issues. Finally after long search I stopped on two plugins
Future Enhancements
- TableSorter
Description : tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell.
I find it very interesting because its very minimal and doesn't changes the DOM much and easily attaches itself VF Pageblocktable. All the version of PageblockTableEnhancer uses this to add Sorting and Pagination capability to a standard VF Pageblocktable. The combination really went well and I guess many of out there are using it now. This plugin is still actively developed and well be enhanced further but I don't think there is much scope to bring new features because its architecture is bit limiting
- Datatables
Description : DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML tableDatatable - looks futuristics isn't it ?
Well Datatables ! everybody out there working on Dynamic Tables can't stop talking about it because of the amazing flexibilty and combination of features this gives. Features like Sorting,Pagination,Search can easily be implemented on very large table just using this table. And there is no boundaries support PDF/CSV export has been recently added and everyday some new plugin is introduced. Its the plugin of the future! Its still actively developed, there are lot of user already using this, new features are added and I see a lot of scope here!
So whats new ?
I have been trying to combine Datatables with Standard VF Pageblock table. But somehow wasn't able to make them work together. But finally I was able to combine them and result is just awesome looking new table!. Yes I was successfully able to combine them and create a new component called PageblocktableEnhancerADV(adv for Advanced, lol I know that sounds a bit funny ) .
I kept both of the plugin alive because people can choose from which one they want. If you like the Default look and feel you can go with PageblockTableEnhancer else you can use the new PageblocktableEnhancerADV.
Personally I feel like there is lot of scope in PageblocktableEnhancerADV, since its based on Datatables there is lot scope and there is a long list feature waiting to be ported.
So Introducing the "PageblocktableEnhancerADV" with the backbone of "PageblocktableEnhancer", same ease of use, same set of parameters, just one line and you are ready to rock!
I kept both of the plugin alive because people can choose from which one they want. If you like the Default look and feel you can go with PageblockTableEnhancer else you can use the new PageblocktableEnhancerADV.
Personally I feel like there is lot of scope in PageblocktableEnhancerADV, since its based on Datatables there is lot scope and there is a long list feature waiting to be ported.
So Introducing the "PageblocktableEnhancerADV" with the backbone of "PageblocktableEnhancer", same ease of use, same set of parameters, just one line and you are ready to rock!
Detail about the PageBlockTableEnhancerADV Component
(If you are using the PageblocktableEnhancer you should be aware about the basic parameters)
(If you are using the PageblocktableEnhancer you should be aware about the basic parameters)
Here is what is new with this plugin
- Pagination Support.
- Support for specifying available page sizes.
- Support for choosing default page size on page load.
- Dynamic Search/filter
- No Coding and Changes Required in existing code.
- Hassle free installation
List o Parameters
- targetPbTableIds : comma-separated Ids of the target Pageblock tables
- paginate : Assign true if you want to use the pagination feature,default value is true.
- pageSizeOptions : A comma seperated list of integer values that will displayed as dropdown for page size
- defaultPageSize : Default page size that needs to be selected (at page load).
Ajax/Rerender support
- This version brings in support for rendering, the earlier version wasn't able to handle this. So incase you are rerendering your table or the parent components, you can call the "initPageBlockTableEnhancerADV()" method from "oncomplete" even of your commandButtons/actionFunctions/actionSupport/commandLink .
<apex:commandButton value="Rerender" reRender="mid" oncomplete="initPageBlockTableEnhancerADV()"/>
Basic Syntax
The basic syntax remains same, just few added params.
<c:PageBlockTableEnhancerADV targetPbTableIds="mid,mid2" paginate="true" defaultPageSize="5" pageSizeOptions="5,10,20,30,40,50,100"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!contacts}" var="con" id="mid">
<apex:column value="{!con.Name}"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!contacts}" var="con" id="mid2">
<apex:column value="{!con.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
PageBlockTableEnhacerADV - Optimized version of Datatable for VF |
Demo,Source And Installation Links : http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000009M3zR
Future Enhancements
- Export to CSV and PDF
- Copy to clipboard
First - So let's start by saying I SOOOO APPRECIATE you doing this!!! Easiest way to better format a table in Salesforce. THANK YOU!!!!
ReplyDeleteSecond - In the old version, the original sort of the data from the original APEX query remained intact. With ADV, the data gets resorted it seems by whatever is the first column. Any tricks how to keep the original sort?
Thanks Robert
I am glad that you liked it. I wasn't sure that if people were using it.
DeleteAnyways the dataTables has its own set of API, I guess I have to dig into it check if something can be done. Don't worry I am working on it, I will post and update once I am done.
Robert, I have a good news for you. I just made some changes in the plugin and now it will retain the initial sorting. You can install the updated version from the Project Page
DeleteYou rock, will try it over the holidays. Thanks. Happy Holidays, Robert
DeleteThanks a lot, worked like a charm!
DeleteI tried using this table and the initial sort changes to the first column.
DeleteWow, I like this component much better...It does duplicate the header and footer panels on a re-render when I just re-render the pageblocktable. When I changed the code to re-render the pageblock that contains the table it worked great without the duplication. Again I'll be glad to send my code, just get me an email address.
ReplyDeleteHOWEVER, when pairing this component up with your new VFUIBlock the block stop functioning. Is there an order I need to have the components declared in my VF page?
Well ok try loading the PageblockEnhancerADV first and then VFUIBlock after the component. Make sure you set "importJQuery" to false for VFUIblock. Well you can use my contact page to submit the code or mail me at my gmail account "avidev9"
DeleteThanks, that worked
DeleteHi Scott , there is a newer version(1.22) of this plugin. With many bug fixes. You can try the same
DeleteI love this, makes my life a lot easier, do you have any suggestions on how to make this work with over 1k records? I have a few in the 1.5-3k range that would be great to use with something like this but I definitely can't think of a quick fix
ReplyDeletePeter, this component is targeted to make the experience with PageblockTable better and but it doesnt actually alter the governor limits associated with a PBT. Well talking about a custom component I can make a new component to show nearly 40K records on a page, but this has to be a custom standalone component and will depend lot more on your requirement and data that you are displaying.
DeleteAvi that sounds like something that we should potentially talk about. I have 2 objects right now that we had our original developer build controllers on for related lists. right now with the field set currently in use the viewstate maxes out at 600 records. would you like me to submit a project form above?
DeleteYeah sure go ahead and submit one then we can discuss the same a bit in detail
DeleteWill do, might be a day or 2 need to finish a few other projects, btw, currently this does not sort by date correctly, it counts it as a string. any idea about how that could be solved?
Deletefound it at http://www.datatables.net/plug-ins/sorting
DeleteI am adding auto detect for date, numbers/currency . Will be there by today /tomorrow. Anyways thanks for reporting
DeletePeter I just released a new version of the plugin with autodetection of datatype
DeleteHi Avi, I am finally getting around to this upgrade but now I am using it for a dozen VF pages, any advice to a non SF wonk on how to upgrade without deleting everything?
DeleteI was able to get around this, sorry for wasting time on that, however i am still stumped by new date time sorting dilemmas I dont get it but "12/3/2013 8:05 AM" still cant sort correctly....
DeleteIf you can hold for a day, I have new version coming up with bug fixes. I think you will need a bit of developer help, I will try to send you instructions
DeleteThanks Avi, I will update the source after I move my custom stuff out of it
ReplyDeleteHello Avi,
ReplyDeleteThanks for a wonderful component. I have tried in the component in firefox and Chrome, it works great. But it seems failing in IE 11. Getting a error as mentioned below
SCRIPT5007: Unable to get property '_unload' of undefined or null reference
File: ext.js, Line: 7, Column: 18230
Can you provide me your valuable thoughts.
Agghh IE 11! They have been always difficult to handle. I currently don't have a windows machine handy. I will try to borrow one soon and let you know about the same
DeleteHow can i disable sorting for particular column of pageBlockTable?
ReplyDeleteCurrently it is not possible to do this in current version. Will be adding this support in subsequent releases.
DeleteIs there a parameter to tell what column to sort by?
ReplyDeleteCurrently it is not possible to do this in current version. I will adding this feature in next releases.
DeleteBy the way thanks for the review!
Is this still planned? I'm lazy and hate mucking around with the comparable interface in the controller in order to get my data to have a default sort.
DeleteSorting on Currency fields not working ?
ReplyDeleteOk so I am not the only one this has happened to....and it is not working on my date field
DeleteOk so I am not the only one this has happened to....and it is not working on my date field
DeleteIs it possible to include this component twice on a VF page? (for different tables)
ReplyDeleteHi. Look like your plugin doesn't support more than 1000 records. Do you have solution for this in last release?
ReplyDeleteHave a look at this post http://blogforce9.blogspot.in/2014/10/showing-more-than-1k-records-using-pbe.html
DeleteI am using this new table in a visual force page which shows opportunity records based on a criteria. I have an Action column with an Edit button. On the click of Edit button, a popup opens up with some fields for users to enter data and save the popup. My question is, the data is getting saved into the table but, I am unable to save the column sort order which was selected before the Edit the button was clicked. Please respond asap.
DeleteIt is not sorting correctly for me as far as dates it sorts by number and when trying to sort my amount field it only sorts by number and not by the thousands place so I have 1,000; 12,000; 2,000; 23,000; 3,000. Please advice.
ReplyDeleteIt is not sorting correctly for me as far as dates it sorts by number and when trying to sort my amount field it only sorts by number and not by the thousands place so I have 1,000; 12,000; 2,000; 23,000; 3,000. Please advice.
ReplyDeleteFacing issue in IE 11, can anyone help me out on this?
ReplyDeleteRerender issue. Please help
ReplyDeleteHi,
ReplyDeleteFunctionality is great, it will be wonderful if it also shows PageNumber.
Thanks,
Dilip Singh
Hi there!
ReplyDeleteI have a little question:
could you
- add integrated option like a "Select All/Deselect All"
- add parameters for disabling - search. paging, ...
Such additions will be very appreciated! :)
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete