2 Replies Latest reply on May 4, 2009 12:11 PM by cencil

    programmatically select specific row in scrollableDataTable

      Hi,

      I'd developed a page that need to select specific row when page load which based on pass in param. Can I do it by using Javascript? but I can't find any function I can call.

        • 1. Re: programmatically select specific row in scrollableDataTa
          ilya_shaikovsky

          You could use selection attribute of scrollable table in order to define initial selection as well as for process it on form submit.

          • 2. Re: programmatically select specific row in scrollableDataTa

            Thanks for your reply.

            I tried to select all row while clicking a button, but the scrollableDataTable do not reflect it, I guess, all row should be selected like pressing Ctrl-A. Below is my code.

            backing bean:

            ...
            public Selection getSelection() {
            return selection;
            }

            public void setSelection(Selection selection) {
            this.selection = (SimpleSelection) selection;
            }

            public String takeSelection() {
            Iterator keys = getSelection().getKeys();
            while (keys.hasNext()){
            // TODO this should be the proper way to get selection key value, but don't work >_<
            // SimpleRowKey key = (SimpleRowKey)iterator.next();
            // TODO I use another way to make it work
            Object key = keys.next();

            shareHolder = shareHolders.get(Integer.parseInt(key.toString()));
            }
            return null;
            }

            public String selectRow() {
            selection = new SimpleSelection();
            selection.setSelectAll(true);
            return null;
            }
            ...

            xhtml:

            <rich:scrollableDataTable id="shSdt"
            value="#{svsShareHolderMaintDetail_backing.shareHolders}"
            var="item"
            selection="#{svsShareHolderMaintDetail_backing.selection}"
            rows="0"
            sortMode="single"
            width="250px" height="160px"
            rowClasses="sdt-odd-row,sdt-even-row">
            <a4j:support event="onselectionchange" action="#{svsShareHolderMaintDetail_backing.takeSelection}"
            reRender="detail"/>

            <rich:column id="name" width="220px" sortBy="#{item.name}" sortOrder="ASCENDING">
            <f:facet name="header">
            <h:outputText value="Share Holders" />
            </f:facet>
            <h:outputText value="#{item.name}"/>
            </rich:column>
            </rich:scrollableDataTable>
            <a4j:commandButton id="selectBtn" value="Select"
            action="#{svsShareHolderMaintDetail_backing.selectRow}"/>
            ...

            Thanks!