Struts2 Jquery Datepicker inside grid column

609 views Asked by At

Can any one help me in including datepicker inside sjg:gridColumn tag.I have included my code below.Whats the Edittype to be used so that a could able to get datepicker.

<sjg:gridColumn name="dateclosed" index="dateclosed"
        title="Date Closed" sortable="false" editable="true"
        edittype="    "/>
1

There are 1 answers

0
Richard Lewan On BEST ANSWER

Rather than use edittype, you can use a nice jQuery datepicker for editing your sjg:gridColumn. This assumes you have jQuery in your project.

First, add the following to your JSP page, above the grid:

<script>
$(document).ready(function(){
    $.struts2_jquery.require("js/base/jquery.ui.datepicker.min.js");
}
</script>

Next, change your sjg:gridColumn:

<sjg:gridColumn name="dateclosed" index="dateclosed" title="Date Closed" 
                sortable="false" hidden="false" hidedlg="false" 
                editable="true" align="center"
                formatter="date" formatoptions="{newformat : 'm/d/Y', srcformat : 'Y/m/d'}" 
                width="100" editrules="{date: true, required:false}" 
                editoptions="{size:12, maxlength: 19, dataInit: function(elem){$(elem).datepicker({dateFormat:'mm/dd/yy'});}}" />

See also: http://jqueryui.com/datepicker/

Alternate implementation: https://code.google.com/p/struts2-jquery/wiki/SearchGrid#A_Grid_Column_with_Datepicker_in_the_search_dialog