Question

I have used Struts2JqueryGrid and I did client side sorting by enable loadonce =true, but it will work while click the column header only. I want shot a column by default on pageload or gridload.

My code is

<sjg:grid id="grid_vehicleedit"
    dataType="json"
    href="%{remoteurl}"
    loadonce="true"
    gridModel="vchlst"
    draggable="false" 
    hoverrows="false"
    sortable="true"
    viewrecords="true"
    sortable="true"
>
    <sjg:gridColumn name="vname" index="vname" sortable="true" title="Vehicle Name" key="true" />  
    <sjg:gridColumn name="imei" sorttype="int" sortable="true" title="Imei" index="imei"   />
    <sjg:gridColumn name="dtype" sortable="true" title="Splitter Type" width="80" index="dtype"/>

</sjg:grid>
Was it helpful?

Solution

Try adding these two attributes to your <sjg:grid> tag:

sortname="vname"
sortorder="asc"

And delete one of the occurrences of sortable="true". So you should end up with:

<sjg:grid id="grid_vehicleedit"
    dataType="json"
    href="%{remoteurl}"
    loadonce="true"
    gridModel="vchlst"
    draggable="false" 
    hoverrows="false"
    viewrecords="true"
    sortable="true"
    sortname="vname" // determines which column you want sorted on gridload
    sortorder="asc" // default is ascending; use desc for descending
    >

    <sjg:gridColumn name="vname" index="vname" sortable="true" title="Vehicle Name" key="true" />  
    <sjg:gridColumn name="imei" index="imei" sorttype="int" sortable="true" title="Imei" />
    <sjg:gridColumn name="dtype" index="dtype" sortable="true" title="Splitter Type" width="80" />

</sjg:grid>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top