3 Replies Latest reply on Feb 12, 2008 4:31 AM by ilya_shaikovsky

    Set selected row in scrollableDataTable from bean

    artmooney

      Hello
      It would be really great if anybody could give me a hint, how to display a scrollableDataTable with a specific row preselected from java code.

      Regards

      Bernd

        • 1. Re: Set selected row in scrollableDataTable from bean
          ilya_shaikovsky

          There shouldn't be any problem. Check scrollableTable example. There the example of simple selection anagement. You may set initial selection in the same maner.

          • 2. Re: Set selected row in scrollableDataTable from bean
            artmooney

            Hi,
            thanks for your reply in the richfaces forum. But I don't get this to work.

            My table looks like this:

            <rich:scrollableDataTable id="results" value="#{patientDetailsController.patient.actions}"
            var="act" height="150px" status="commonstatus"
            selection="#{patientDetailsController.selection}"
            reRender="actionDetailsParent" sortMode="single"
            binding="#{patientDetailsController.table}">

            <a4j:support event="onselectionchange" reRender="resultsChildrenPanel, actionDetailsParent"
            actionListener="#{patientDetailsController.takeSelection}"/>

            I can access the selected rows after the user has selected them in the browser, but I don't manage to preselect e.g. the first row when the table is initially rendered. By the way what is this rowKeyVar attribute?

            I tried

            public HtmlScrollableDataTable getTable()
            {
            LogFactory.getLog(getClass()).info("getTable");
            ((SimpleSelection)table.getSelection()).addKey(0);

            return table;
            }

            but this doesn't have any effect. Could you please give me some more hints. In the mentioned example I haven't found anything useful.

            Regards,

            Bernd

            • 3. Re: Set selected row in scrollableDataTable from bean
              ilya_shaikovsky

              using demosite sample I've added

              public DataTableScrollerBean() {
               selection.addKey(new SimpleRowKey(0));
               selection.addKey(new SimpleRowKey(1));
               selection.addKey(new SimpleRowKey(2));
              
               }


              and my table looks like
               <rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="400px"
               width="700px" id="carList" rows="40" columnClasses="col"
               value="#{dataTableScrollerBean.allCars}" var="category" selection="#{dataTableScrollerBean.selection}">


              First three rows selected after initial page rendering.