Filter and remove duplicates contents of Dropdown list in create new

Filter and remove duplicates contents of Dropdown list in create new

ginacargileginacargile Posts: 17Questions: 3Answers: 0

Based on the current code I have listed here:
https://datatables.net/forums/discussion/37068/saving-a-dropdown-field-value-and-and-id-in-the-same-table?new=1

My dropdown list has values like "Door", "Door 1", "Front Door", "Front Door 1", "Side Door 1" and I need to cut the # value off the end's and then remove duplicates.

I've looked at GetFormatter for server side. I figured it would have to be done client side, but, what event and how exactly?

Thanks!

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Are you using the Field->options() method to get the options, or something else? There is a formatter option for the options, which you can use to modify the labels.

    Allan

  • ginacargileginacargile Posts: 17Questions: 3Answers: 0

    Yes, I'm using field .options. I don't know how to use the formatter to format the values the way I want. ?

    using (var db = new Database(dbtype, conn))
                    {
                        tempInstanceNames d = new tempInstanceNames();
    
                        response = new Editor(db, "tempInstanceNames")
                       .Model<JointempInstanceNamesModel>()
    
                       .Field(new Field("tempInstanceNames.InstanceNameID")
                       .Options("tlkInstanceNames", "ID", "InstanceName")
                       .Validator(Validation.DbValues(new ValidationOpts { Empty = true }))
                       )
                       .Field(new Field("tempInstanceNames.LocationSpaceID")
                           .Options("tlkLocationSpaces", "ID", "LocationSpace")
                           .Validator(Validation.DbValues(new ValidationOpts { Empty = true }))
                       )
                       .Field(new Field("tempInstanceNames.SubLocationSpaceID")
                            .Options("tlkSubLocationSpaces", "ID", "SubLocationSpace")
                           .Validator(Validation.DbValues(new ValidationOpts { Empty = true }))
                        )
                         .Field(new Field("tlkInstanceNames.InstanceName")
                            .Options("tlkInstanceNames", "ID", "InstanceName")
                           .Validator(Validation.DbValues(new ValidationOpts { Empty = true }))
                        )
                       .LeftJoin("tlkLocationSpaces", "tlkLocationSpaces.ID", "=", "tempInstanceNames.LocationSpaceID")
                       .LeftJoin("tlkSubLocationSpaces", "tlkSubLocationSpaces.ID", "=", "tempInstanceNames.SubLocationSpaceID")
                       .LeftJoin("tlkInstanceNames", "tlkInstanceNames.ID", "=", "tempInstanceNames.InstanceNameID")
                       .Where("tempInstanceNames.LocationID", locationID)
                       .Process(request)
                       .Data();
                    }
    
  • ginacargileginacargile Posts: 17Questions: 3Answers: 0
    edited August 2016

    I didn't realize you could do an inline select! I found this link.
    https://datatables.net/forums/discussion/27856/editor-net-field-options-method

    If there is a better way, please let me know.

    Full code here:

    .Field(new Field("tlkInstanceNames.InstanceName")
                            .Options(() => db
                            .Sql("select distinct SUBSTRING(inn.InstanceName,0,PATINDEX('%[0-9]%',inn.InstanceName)) as label, SUBSTRING(inn.InstanceName,0,PATINDEX('%[0-9]%',inn.InstanceName)) as value FROM dbo.tblInstances i LEFT JOIN tlkinstancenames inn ON i.InstanceNameID = inn.ID WHERE SUBSTRING(inn.InstanceName, 0, PATINDEX('%[0-9]%', inn.InstanceName)) IS not null ORDER BY label,value")
                            .FetchAll()
                            )
                        )
    

    Thanks!

  • ginacargileginacargile Posts: 17Questions: 3Answers: 0
    edited August 2016

    Thanks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    For complex queries that looks about as good as it gets :-)

    Allan

This discussion has been closed.