Component index
Section index

Component sample


Search

	/*
	    Here is a typical/simple application showing column sorting.
	*/
	<mod>
	static void samples_editrecords_sorted(int nb)
	{
	    <glocal>
	        int nb;
	    </glocal>
	    glocal.nb = nb;
	    <call editrecords>("records","Some sortable records",help_nil);
	        <f head>
	            newf_head ("ID\tDescription\tDate");
	            sortable();
	        </f>
	        <f load>
	            // We sort each colums independantly (no useful)
	            SSTRINGS nums,descs,dates;
	            for (int i=0; i<glocal.nb; i++){
	                char buf1[100];
	                sprintf (buf1,"%03d",i);
	                nums.add (new SSTRING(buf1));
	                SSTRING *s = new SSTRING;
	                s->setfromf ("This is record %d",i);
	                descs.add (s);
	                s = new SSTRING;
	                s->setfromf ("%02d/10/2000",i);
	                dates.add (s);
	            }
	            if (order != SORT_NONE){
	                switch (column){
	                case 0:
	                    nums.sort();
	                    break;
	                case 1:
	                    descs.sort();
	                    break;
	                case 2:
	                    dates.sort();
	                    break;
	                };
	                if (order == SORT_DESC){
	                    nums.invert();
	                    descs.invert();
	                    dates.invert();
	                }
	            }
	            for (int i=0; i<glocal.nb; i++){
	                new_menuitemf (nums.getitem(i)->get(),"%s\t%s"
	                    ,descs.getitem(i)->get(),dates.getitem(i)->get());
	            }
	        </f>
	        <f editone>
	            xconf_notice ("Editing record %d",no);
	        </f>
	        <f clickhead>
	            if (state.leftb){
	                selectsort (head);
	            }else if (state.rightb){
	                // Contextual menu
	                xconf_notice ("Put a popup here");
	            }
	        </f>
	    </call>
	}
	</mod>