Filtering directly on the table

Help
Juan Parra
2008-11-14
2013-04-29
  • Juan Parra

    Juan Parra - 2008-11-14

    Hello
    <div><br />In JPivot, I wish to introduce a change in navigation to allow filtering of data using the Navigator and extending TableComponentExtensionSupport.<br />The idea is<br /><br /><a href="http://4.bp.blogspot.com/_usNw2Z93LqU/SR2W4wfdm1I/AAAAAAAAAAM/ZeJnBdrXnXA/s1600-h/jpivot.gif"><img id="BLOGGER_PHOTO_ID_5268533040927054674" style="WIDTH: 320px; CURSOR: hand; HEIGHT: 198px" alt="" src="http://4.bp.blogspot.com/_usNw2Z93LqU/SR2W4wfdm1I/AAAAAAAAAAM/ZeJnBdrXnXA/s320/jpivot.gif" border="0" /></a></div><div></div><br /><div>If the user clicks on the icon <a href="http://4.bp.blogspot.com/_usNw2Z93LqU/SR2YSoCSn5I/AAAAAAAAAAU/v_O4_cavTo0/s1600-h/jpivot2.gif"><img id="BLOGGER_PHOTO_ID_5268534584845442962" style="WIDTH: 11px; CURSOR: hand; HEIGHT: 13px" alt="" src="http://4.bp.blogspot.com/_usNw2Z93LqU/SR2YSoCSn5I/AAAAAAAAAAU/v_O4_cavTo0/s320/jpivot2.gif" border="0" /></a> that will automatically filter the data.</div><div> </div>

     
    • Juan Parra

      Juan Parra - 2008-11-14

      my implementation is

      public class FilterMemberUI extends TableComponentExtensionSupport implements ModelChangeListener {
      .....

        public void initialize(RequestContext context, TableComponent table) throws Exception {
         
          super.initialize(context, table);
          table.getOlapModel().addModelChangeListener(this);

          table.getDispatcher().addRequestListener(null, null, dispatcher);

          AxisBuilder rab = table.getRowAxisBuilder();
          DomDecorator rhr = new DomDecorator(rab.getSpanBuilder());
          rab.setSpanBuilder(rhr);

          AxisBuilder cab = table.getColumnAxisBuilder();
          DomDecorator chr = new DomDecorator(cab.getSpanBuilder());
          cab.setSpanBuilder(chr);

        }
      ....

        class DomDecorator extends SpanBuilderDecorator {

          DomDecorator(SpanBuilder delegate) {
            super(delegate);
          }

          public Element build(SBContext sbctx, Span span, boolean even) {
            Element parent = super.build(sbctx, span, even);

            if (!enabled || !renderActions)
              return parent;

            String id = DomUtils.randomId();
            if (isPosibleFilter(span)) {
              Element elem = table.insert("drill-expand", parent);
              elem.setAttribute("id", id);
              elem.setAttribute("img", "filter-member-aviable");
              elem.setAttribute("title", "Filtrar");
              dispatcher.addRequestListener(id, null, new FilterdHandler(span));
            }
            return parent;
          }
        }

      ....

        static boolean isPosibleFilter(Span span) {
         

          if (!span.isMember()) return false;
         
          Member member = (Member) span.getMember().getRootDecoree();
          if (member.isAll())  return false;
         
          if (member instanceof MondrianMember ){
              MondrianMember mondrianMember = (MondrianMember)member;
              if (mondrianMember.getMonMember().isMeasure()) return false;
          }
          Position position = (Position) span.getPosition().getRootDecoree();
          return indexOf(position.getMembers(), member) >= 0;
        }

        protected void filter(Span span, RequestContext context) throws OlapException, Exception {
         

            MondrianMember mondrianMember = (MondrianMember) span.getMember().getRootDecoree();

            HttpSession session = context.getSession();

            Navigator navigator = (Navigator) session.getAttribute("navi01");

            Hierarchy hierarchy = span.getMember().getLevel().getHierarchy();

            HierarchyNavigator hierarchyNavigator = navigator.getHierarchyNav();

            hierarchyNavigator.initializeCategories();

            HierarchyItem hi = hierarchyNavigator.findHierarchyItem(hierarchy);

            List list = new ArrayList();

            list.add(mondrianMember);

            hi.setSelection(list);

            hierarchyNavigator.getAcceptHandler().request(context);

            hierarchyNavigator.setEditing(true);
            
        }

      }

       
    • Juan Parra

      Juan Parra - 2008-11-14

      this works but I had to change in the class HierarchyNavigator to public initializeCategories I think this is not good, any recommendation?

       
    • Carlos Dias

      Carlos Dias - 2008-11-14

      Sorry Juan, but I don't understand your question? Can you explain?!

       
    • Juan Parra

      Juan Parra - 2008-11-14

      Hi Carlos,

      A user asked me to filter directly into the data table through a icon.

      My idea was to use the HierarchyNavigator and HierarchyItem able to filter the data and that these changes are reflected in the Navigator.

      the click of the user returns the Span and through which I can get the MondrianMember and Hierarchy

      I could finally get the HierarchyItem using the method findHierarchyItem (hierarchy) of class HierarchyNavigator

      so we can enter the filter using the method setSelection ([MondrianMember ...]) of class HierarchyItem

      The problem was that the method findHierarchyItem (hierarchy) requires the field "List categories" not null

      This operation is done by the private method initializeCategories

      I had to switch to public and call initializeCategories before findHierarchyItem to make it work

      You can see the method protected void filter

      I think that change is not good and if there is any other way to perform this operation without having to change the existing source code.

      Thank you.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks