Announcement

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

    How to set the initial filter settings in a Listgrid

    I have created a Listgrid with filtering options. This works. I now need to prepopulate the start filter fields.

    I am using a javascript for smartclient.

    Initially it has no filter values.

    So list grid is :

    isc.ListGrid.create({
    ID : "cmUserList",
    dataPageSize: 100,
    drawAheadRatio: 1,
    // width : "40%",
    // height : 300,
    alternateRecordStyles : true,
    dataSource : "CmcrmUsers",
    autoFetchData : true,
    fields : [ { name: "contactName",title : "Contact Name" },
    { name: "email" , title: "E-mail" },
    { name: "id" , title: "id" },
    { name: "businessPartnerName", title: "Business Partner"}
    ],

    showFilterEditor : true,
    filterOnKeypress: true

    })
    I would like to ensure the filter starts with contactName as a value eg "Tom Smith"

    is this possible ?

    Sorry I have not listed the smartclient version . Can we see this value in the console ?

    #2
    When using autoFetchData:true, just provide ListGrid.initialCriteria with the criteria values you want.

    Yes, the version appears in the lower left-hand corner of the Developer Console.

    Comment


      #3
      initialCriteria set value in filter control

      Thanks for that. I now have used the following:

      initialCriteria: {

      criteria: [
      { fieldName: "contactName", operator: "equals", value: "Joe" }

      ]
      }

      This sets the criteria for the request generated for the Datasource, but does not set the value shown in my Listgrid. This remains blank but a criteria item is created for r this which is then included in the send to the datasource. ie in the filter grid for columnField contactName, the value is blank.

      How to I just initially set the value that should be shown in the relevant place. Also I notice if I use the above the criteria remains in place, ie does not get cleared.

      Any ideas ?

      Comment


        #4
        The default criteria produced by the FilterEditor would use the "substring" operator, so this Criterion cannot be edited by the FilterEditor.

        To create a match between the initial criteria you are providing and the FilterEditor, you can either:

        1. set the operator on this Criterion to "substring"

        OR

        2. set FormItem.operator for the listGridField to "equals" via field.filterEditorProperties

        OR

        3. set the default textMatchStyle to "exact" via listGrid.autoFetchTextMatchStyle

        Most likely you want substring filtering (the most common) so you want #1.

        Comment


          #5
          Originally posted by Isomorphic View Post
          The default criteria produced by the FilterEditor would use the "substring" operator, so this Criterion cannot be edited by the FilterEditor.

          To create a match between the initial criteria you are providing and the FilterEditor, you can either:

          1. set the operator on this Criterion to "substring"

          OR

          2. set FormItem.operator for the listGridField to "equals" via field.filterEditorProperties

          OR

          3. set the default textMatchStyle to "exact" via listGrid.autoFetchTextMatchStyle

          Most likely you want substring filtering (the most common) so you want #1.
          Thanks for that. I have tried 1. ie.

          initialCriteria: {


          criteria: [
          { fieldName: "contactName", operator: "substring", value: "Joe" },

          {fieldname: "businessPartnerName", operator: "substring", value: "" }
          ]
          }

          What happens is this criteria is correctly sent to the server as two criteria json objects where I can retrieve the correct details. However the filter input fields are not showing the value of "Joe" . Is there no way of getting this value set to what I want . ie just the filter text to show in the grid input field.

          For the 2nd Option ..

          I cannot try this because I cannot see how the FormItem can be set up in javascript. o I set it in the initWidget for the ListGrid ? Is there an example of how this is done ?



          3. also does not do it.

          Comment


            #6
            1 & 3. This approach works fine in our testing

            2. We already indicated how this is done: field.filterEditorProperties

            Comment


              #7
              Initial criteria

              So is it correct the way I set the Initial grid filter option. What I am saying is that the grid filters correctly on these initial settings but the text of this does not appear in the filter input fields. ie grid correctly populated but it does not show what the initial setting was. Does yours also set the text in the filter input fields ?

              My smartclient version is : SNAPSHOT_v8.3d_2012-05-26/LGPL Development Only (built 2012-05-26)

              Comment


                #8
                Ug, this is why the forums tells you to always post your version. Your build pre-dates some of these criteria editing behaviors. Try 9.0 or 9.1.

                Comment


                  #9
                  Iḿ stuck with that version

                  I have to use that version , it is supplied with the product I have to modify. It looks like smartclient has no easy way or it is not easy to find how I just set text in an input field of the filter.
                  when you say filterProperties what would be the javascript property you set. ie for a Listgrid with fields of name and description, and filertering set on , what is the exact code you would use with filterProperties to set the text value in the filter above the name column ?

                  is it something like :

                  filterProperties: { name: "name", "value" , "avalue"} ,

                  I cannot see in the guide how filter properties are actually set.

                  Comment


                    #10
                    I had a similar need to show the initalCriteria as values in the fitler editor so that the user has clarity on what is currently the active filtering because the initialCriteria attribute does not set the value in the fitler editor fields.
                    I solved it using a combination of initialCriteria as indicated by Isomorphics response above and then used the "drawn" event to make the initial criteria visible in the filter editor so that subsequent changes made by the user to the filters are not repeatedly overwritten.
                    In this sample:
                    https://www.smartclient.com/smartcli...tchOperationFS

                    I used this code in the fetch.js tab to show how it works:
                    Code:
                    isc.ListGrid.create({
                        ID:"dsListGrid",
                        width: "100%",
                        height: "100%",
                        autoFetchData: true,
                        dataSource: "supplyItem",
                        showFilterEditor: true,
                        initialCriteria: {
                          criteria: [
                           { fieldName: "units", operator: "equals", value: ['Set', 'Tin'] },
                          ]
                        },
                        drawn: "this.setFilterEditorCriteria({ units: ['Set', 'Tin']});"
                    });

                    Comment


                      #11
                      initialCriteria are shown in the filterEditor automatically, if you define them correctly - in this case, for a single criterion, you just need:

                      Code:
                      initialCriteria: { fieldName: "units", operator: "equals", value: ['Set', 'Tin'] },

                      If you have more than one criterion to apply, use AdvancedCriteria:

                      Code:
                          initialCriteria: {
                              constructor: "AdvancedCriteria",
                              operator: "and",
                              criteria: [
                                      { fieldName: "units", operator: "equals", value: ['Set', 'Tin'] },
                                      { ... other criterion ... }
                              ]
                          },
                      Last edited by Isomorphic; 2 Oct 2021, 19:35.

                      Comment


                        #12
                        Awesome - thanks - much simpler.

                        Comment

                        Working...
                        X