Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Using displayField to non foreignKey field

    Hello Guys,

    I am facing a problem with displayField attribute of listGridField.


    I am using the below code :

    Code:
    <field name="selected_ids" type="text" displayField="selectedIdDescriptions"/>
    <field name="selectedIdDescriptions" type="text" customSelectExpression="IFNULL((select GROUP_CONCAT(user.user_name order by user.user_name asc) from my_user where user.user_id in(user_groups.user_ids)),'')"/>
    
    ListGridField field = new ListGridField("selected_ids");
    1. selected_ids is my database column.
    2. selectedIdDescriptions is not a database column and is just used to fetch the id descriptions
    My table contains data as comma separated list of id's in columns. So I want the field to be selected_ids with displayField as their string. The reason why I want it work this way is to let the Grid to Grid copy functionality to work fine. If I use
    Code:
    ListGridField field = new ListGridField("selectedIdDescriptions");
    then the grid to grid copy will send only the description not the ID and it breaks.

    Problem : If I used the above code , the framework is sending another fetch call along with grid fetch without any criteria for the same datasource and it hangs as it has alot of data in it. Is there.

    Solutions I tried :
    1. displayValueFromRecord="true"
    2. useLocalDisplayFieldValue="true"
    3. autoFetchDisplayMap="false"

    I have gone through the displayField documentation that says this attribute is ideally used for foreign key association fields. Is there any way I can stop this extra fetch call? In short I want displayField to be set as a field which is not a foreignKeyAssociation.

    Thanks in advance.






    #2
    displayField on its own won't do this, but configuring an optionDataSource on a ListGridField would do it.

    If you think just using displayField is responsible, work toward creating a minimal test case and you'll find the real problem.

    Comment


      #3
      Thanks Isomorphic ,
      I tried configuring optionDataSource on listgrid field but still it's sending the extra fetch.


      Code:
              ListGridField field = new ListGridField("selectedIdDescriptions");
              field.setOptionDataSource(DataSource.get("MyDataSource"));
              field.setAutoFetchDisplayMap(false);
              field.setDisplayValueFromRecord(true);
      Still same problem.

      Comment


        #4
        What we said was that optionDataSource could be a cause of the unwanted request, so it would be something to remove rather than something to add.

        As far as next steps, you already have our advice:

        If you think just using displayField is responsible, work toward creating a minimal test case and you'll find the real problem.

        Comment


          #5
          I just found out that the extra fetch are going when I set setShowFilterEditor(true), otherwise it works fine.
          I have resolved the issue for few fields by setting:

          Code:
          field.setFilterEditorType(new TextItem());
          But there are few fields for which I need to show filter editor as well. By setting the setFilterEditorProperties on those fields. The issue is resolved.
          Thanks Isomorphic
          Last edited by kamet4u; 28th Sep 2020, 23:57.

          Comment


            #6
            Here again, just enabling the filterEditor will not cause a fetch for a field that specifies displayField. You would need optionDataSource or FK settings that would cause a SelectItem or ComboBoxItem to be used, and then, that component would potentially make a fetch when created, but would not normally make a full DataSource fetch unless yet further settings had been specified (such as useLocalFiltering).

            Comment


              #7
              Hi all,

              been reading this thread. kamet4u Are you sure you need the selected_ids in your code (e.g. for ID filtering?)? If not, why don't you use just the selectedIdDescriptions field?
              I think we have a similar setup somewhere (show assigned n:m products in the masterdata row), but this is pretty difficult to get right if you want filtering to be fast as well.

              Isomorphic: The case the OP describes I had as well. Once you have a SelectItem (I don't know how they got it), it will try fetch the whole DS, see the testcase below in this sample (v12.0p_2020-09-29). I assumed this is correct, but according to your #6 it seems this is not to be the case:
              Code:
              isc.ListGrid.create({
                  ID:"dsListGrid", 
                  width: "100%",
                  height: "100%",
                  autoFetchData: true,
                  dataSource: "supplyItem",
                  showFilterEditor: true,
                  fields:[
                      {name:"SKU", filterEditorType:"SelectItem"}, // Full DS fetch
                      {name:"itemName", filterEditorType:"SelectItem", valueMap: ['Yes', 'No']}, // No fetch
                      {name:"description"},
                      {name:"category"}
                  ],
                  showFilterEditor: true
              });
              If you define a valueMap, the fetch goes away.

              Best regards
              Blama

              Comment


                #8
                Blama, as we explain above, you would need a setting such as optionDataSource or foreignKey in order to get a SelectItem.

                Then, once you have a SelectItem, there would be a fetch, but not for all records, not unless there are yet more settings this user is declining to mention. Also, the timing of the fetch can be controlled.
                Last edited by Isomorphic; 30th Sep 2020, 09:01.

                Comment


                  #9
                  Ah, yes. True. By bad.
                  I have it in a setting where a user chooses a FormItem and can give with a valueMap, if SI/CBI is selected. Then the valuelist must be filled and if the user does not do this, then this unbounded fetch happens. But that is of course bad usage.

                  Best regards
                  Blama

                  Comment


                    #10
                    Hi Blama , Isomorphic ,

                    Yes I need the field to be Id point to displayField for description to be shown on grid because I want grid to grid copy paste to work. Also I have not defined the optionDataSource because in edit mode of the cell I open a window with options not the dropdown. User selectes the data from window and when we select ok the data is set in the grid using setEditValue() method. I just noticed that as soon as I call setEditValue on this field there is again a fetch issued by gird.

                    Comment


                      #11
                      As covered repeatedly above, your description doesn’t match what actually happens, so there are probably other settings involved that you aren’t showing us.

                      If you want this looked at further, you will need to create a minimal, ready-to-run test case that demonstrates a problem.

                      Comment


                        #12
                        Hi Isomorphic ,
                        I have editor configured like below :

                        Code:
                         setEditorCustomizer(context -> {
                          final ListGridField field = context.getEditField();
                           if (field.getName().equals("selected_ids")){
                                return new CustomTextItem();
                            }
                        });
                        
                        
                        /*TextItem to be returned to editorcusotmizer*/
                        public class CustomTextItem extends TextItem {
                        
                             public CustomTextItem() {
                                final CustomWindow popUp = new CustomWindow();
                                addClickHandler(event -> {
                                    popUp.show();
                                });
                        
                        /*tried below properties but no success*/
                                setDisplayField("selectedDescription");
                                setValueField("selected_ids");
                                setUseLocalDisplayFieldValue(true);
                        
                        /*this resolved the extra fetch issue*/
                                setFetchMissingValues(false);
                        
                            }
                        }
                        
                        
                        /*Window with OK button to add edit values in grid*/
                         public class CustomWindow extends Window {
                         public CustomWindow(ListGrid grid){
                         IButton okButton = new IButton();
                                     okButton.addClickHandler(event -> {
                                     grid.setEditValue(rowNum,"selected_ids", "1,2,3");
                                     grid.setEditValue(rowNum,"selectedDescription", "A,B,C");
                                });
                        addChild(okButton);
                             }
                        }

                        I noticed the extra fetch were initiated by the TextItem to fetchMissingValues as soon as I set any value using setEditValue.
                        Adding
                        Code:
                           setFetchMissingValues(false);
                        resolved the extra fetch issue.

                        Now everything is fine except that the field is showing the comma separated id's instead of the descriptions.
                        As soon as I go out from edit mode it shows the description correctly and sends the update call.

                        I tried below properties for this id issue but no success:
                        Code:
                                setDisplayField("selectedDescription");
                                setValueField("selected_ids");
                                setUseLocalDisplayFieldValue(true);
                        Last edited by kamet4u; 5th Oct 2020, 02:06.

                        Comment


                          #13
                          So again, all of these findings suggest that foreignKey or optionDataSource are in fact being specified somewhere, and it continues to be useless to point small, isolated snippets. So again:

                          If you want this looked at further, you will need to create a minimal, ready-to-run test case that demonstrates a problem.

                          Comment


                            #14
                            Hi Isomorphic ,
                            I created a simple grid to demonstrate this issue. PFB the code used.


                            Code:
                            <field name="ids" type="text" displayField="descriptions" />
                            <field name="descriptions" type="text"/>
                            
                            
                                 final ListGrid myGrid = new ListGrid(DataSource.get("MyDataSource"));
                            
                            /*Temporary added this to demonstrate the issue.  This is the exact scenario that happens when  I select Id's in customized box and click ok.  This is how I am providing both the id and displayField values to edit values. This shows Id's instead of description till the time row is in edit mode. As soon as I  click outside the row shows the correct description.
                            How can I enable grid to show the manually set display values instead of IDS here ? */
                                            myGrid.addEditorEnterHandler(e -> {
                                                myGrid.setEditValue(e.getRowNum(), "ids", "122,123,124");
                                                myGrid.setEditValue(e.getRowNum(), "descriptions", "a,b,c");
                                            });
                            
                                            myGrid.setEditorCustomizer(context -> {
                                                if (context.getEditField().getName().equals("ids")) {
                                                    TextItem item = new TextItem();
                                                    /*As I don't want to populate dropdown, Here I open a customized window*/
                                                    item.setFetchMissingValues(false);
                                                    item.setUseLocalDisplayFieldValue(true);
                                                    return item;
                                                }
                            
                                                return context.getDefaultProperties();
                                            });

                            Thanks

                            Comment


                              #15
                              If you want this looked at further, you will need to create a minimal, ready-to-run test case that demonstrates a problem.
                              This is not a standalone test case. This is just an isolated code snippet, which we have already explained is useless.

                              Comment

                              Working...
                              X