Announcement

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

    How to show different values in select item field of ListGrid for each row?

    SC version - 8.0
    Problem - Client Side
    Problem One Liner - How to show different values in select item field of ListGrid for each row.

    Detail - I have a list grid which shows the details of user groups of my applications. Each row in ListGrid shows the details of different user groups. ListGrid have one field as Group Leader. Group Leader (select item) can be any one of the users in that group. I want that in Group Leader field all users of a group (rather than all users existing in application) should be shown. As each row represents different user group, so Group Leader field for each row will have different drop down values. How to get different drop down values for Group Leader for each row?

    Just info, I am using optionDataSource in ListGridField for Group Leader.

    I would appreciate is someone can show some example code.

    Regards,
    Gaurav

    #2
    This is essentially the same as the Databound Dependent Selects example, except the value to use as criteria comes from the current record instead of from another SelectItem.

    Comment


      #3
      Thanks Isomorphic for your response.

      I am able to achieve most of it with your suggestion, just having one minor issue as below.

      When I use two dependent select items in ListGrid, both dependent on primary key of ListGrid of Row (in my case group_id) and fetching valuemap from same optionDataSource, I fail to use the successfully filter on valuemap driven from optionDataSource. When I have just one dependent select item in ListGrid, then also the same problem. In both these cases select item shown all the valuemap from optionDataSource (does not filter).

      But if I have one dependent select and one non-dependent select, both fetching valuemap from same optionDataSource, then dependent select shows the values based on group_id (works fine as it filters and do not show other valumap entries). I am not able to understand why such wired behavior in above two cases.

      Below is the code snippet from ListGrid and related DataSource, which will show how I am using dependent select:

      Code:
      isc.RestDataSource.create({
          ID:"af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_DS",
          fields:[
      		{
      			type:"int", 
      			title:"User Group Id", 
      			required:true,
      			primaryKey:true,
      			hidden:true,
      			name:"group_id"
      		},
      		{
      			type:"select", 
      			title:"Primary Group Leader", 
      			autoFetchDisplayMap:true,
      			optionDataSource:af_ugm_<?php echo $user_id?>_all_users_DS,
      			foreignKey:af_ugm_<?php echo $user_id?>_all_users_DS.user_id,
      			valueField:"user_id",
      			displayField:"display_name",
      			getPickListFilterCriteria : function () {
      	            var current_row_num = af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_Grid.getEditRow();
      	            var group_id = af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_Grid.data.getProperty("group_id").get(current_row_num);
      	            if (group_id != "") {
      	            	return {group_id:group_id};
      	            }
      	        },
      			name:"primary_group_leader_user_id"
      		},
      		{
      			type:"select", 
      			title:"Secondary Group Leader", 
      			autoFetchDisplayMap:true,
      			optionDataSource:af_ugm_<?php echo $user_id?>_all_users_DS,
      			foreignKey:af_ugm_<?php echo $user_id?>_all_users_DS.user_id,
      			valueField:"user_id",
      			displayField:"display_name",
      			getPickListFilterCriteria : function () {
      	            var current_row_num = af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_Grid.getEditRow();
      	            var group_id = af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_Grid.data.getProperty("group_id").get(current_row_num);
      	            if (group_id != "") {
      	            	return {group_id:group_id};
      	            }
      	        },
      			name:"secondary_group_leader_user_id"
      		},
          ],
          dataFormat:"json",
          addDataURL:"restcalls/data_operations/function/addUserGroup",
          fetchDataURL:"restcalls/data_operations/function/fetchAllUserGroupDetails",
          updateDataURL:"restcalls/data_operations/function/updateUserGroupDetails"
      })
      
      
      
      isc.ListGrid.create({
          height:"100%",
      	dataSource:"af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_DS",
          ID:"af_ugm_<?php echo $user_id?>_UserGroupManagement_UserGroupDetails_Grid",
          width:"100%",
      	canEdit:true,
      	canSort:true,
          wrapCells: true,
          autoDraw:true,
      	autoFetchData:true,
          selectionType:"simple",
          filterOnKeypress:true,
          showFilterEditor:true,
      	fixedRecordHeights: false,
          alternateRecordStyles:true,
          overflow:"auto"
      })

      Comment


        #4
        Sounds like the Criteria you're assembling or the data returned are incorrect. Use the RPC tab to see the requests and responses, and also use logging to check the values you are returning in getPickListFilterCriteria()

        Comment


          #5
          Even after lot of investigation I am not able to catch the issue. I am returning the right filter criteria from getPickListFilterCriteria(). Attached are the alert() window messages of what I am returning from getPickListFilterCriteria(). Also attaching the snapshot of what filed values (valuemap) I am seeing in select item.

          Below is the JSON response from server for optionDataSource. As per JSON response, it contains 2 records and both these records are shown in select item's drop down, no filtering has been done based on criteria returned by getPickListFilterCriteria().

          Filtering do happen only in one case, when I have two select items, one dependent select and another non-dependent select on same optionDataSource. If I make both select items as dependent select items, criteria filtering fails and select items show all values in optionDataSource.

          Below is the data returned by optionDataSource
          Code:
          {response:{status:0, startRow:0, endRow:2, totalRows:2, data:[{"group_id":"1","org_id":"2","group_name":"Administrators","role_id":"2","primary_group_leader_user_id":"14","secondary_group_leader_user_id":"14","group_description":"Group of administrator users. Users in this group will normally have full rights.","num_of_members":"4"},{"group_id":"2","org_id":"2","group_name":"Sales Agents","role_id":"1","primary_group_leader_user_id":"2","secondary_group_leader_user_id":"2","group_description":"Group of sales agent users.","num_of_members":"5"}]}}
          I know its strange, but not able to figure out where is the issue. Can it be a bug?

          Regards,
          Gaurav
          Attached Files

          Comment


            #6
            Probably not, but whether you believe it is or not, what you should try to do is create a standalone test case that reproduces the issue. If it's in fact an application-level issue, you will discover this in the process of trying to create a standalone test case.

            Comment


              #7
              Thanks for guiding me.
              I got the issue resolved. It was my mistake. getPickListFilterCriteria() was returning the right criteria, but I was not handling the return value correctly to fetch records based on criteria.

              I was under impression that optionDataSource will anyhow fetch all the records and criteria returned by getPickListFilterCriteria() will be applied only when select item fetch values locally from optionDataSource. It was my misunderstanding, which ate my 3 days :(

              Anyway thanks for great support !

              Gaurav

              Comment

              Working...
              X