Column search in editor column of type 'select'

Column search in editor column of type 'select'

jgessingerjgessinger Posts: 38Questions: 6Answers: 0
edited August 2016 in Editor

Hello Allan,

I have a column of type 'select' in my editor instance, which is populated by the controller with integer IDs as 'option' value and strings as 'option' text. Now when I try to search in this column with ...column(...).search(...).draw(...) it is just searching inside the option values, but I need the results for the texts.

Maybe one solution for me is to create another hidden column, where I will put out just the texts and where I can search in. But is there another possible (better) solution?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Can you give me a link to the page please? As you will be able to see in this example it should search the label if that is what is displayed in the DataTable.

    Allan

  • jgessingerjgessinger Posts: 38Questions: 6Answers: 0

    I dont have an accessable example sorry.

    Ok your example is nice. There you just take the 'name' property for output in datatables and the 'id' for the editor instance, to change the value.

    In my version I used the 'id' also for the datatables output and then changed the output text with help of the render method. But the result is, that I cant search the texts but just the ids.

    So the main problem when I change it to the way you solved it in your example would be, that I cant use the inline edit feature, because the field isnt connected to the right editor field (because of a different field name, if I understand this right?).

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    In my version I used the 'id' also for the datatables output and then changed the output text with help of the render method.

    Can you show me that render method? Actually, if you could just show me the full initialisation and also some of the data you are using that would be great.

    Thanks,
    Allan

  • jgessingerjgessinger Posts: 38Questions: 6Answers: 0

    Ok here my abstract example:

    The controller part looks like this:

    ...
    .Field(new Field("TestTable.OptionId")
        .Options("OptionsTable", "Id", "Name")
    )
    .Field(new Field("OptionsTable.Name"))
    .LeftJoin("OptionsTable",
        "TestTable.OptionId",
        "=",
        "OptionsTable.Id")
    ...
    

    In my script I init the editor:

    ...
    fields: [
        ...
        {
            name: 'TestTable.OptionId',
            label: 'Option ID',
            type: 'select'
        }
        ...
    ]
    ...
    

    and dataTables:

    ...
    columns: [
        ...
        {
            data: 'TestTable.OptionId',
            title: 'Option ID',
            render: function (data, type, row) {
                return row.OptionsTable.Name;
            }
        }
        ...
    ]
    ...
    

    The result is, that the column search just searchs inside the TestTable.OptionId items but not the OptionsTable.Name. But I also need the inline edit feature for the editor, so I dont know if I just can change the dataTables columns -> data value from i.e. 'TestTable.OptionId' to 'OptionsTable.Name'.

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Answer ✓

    Use:

    {
      data: 'OptionsTable.Name',
      editField: 'TestTable.OptionId',
      title: 'Option ID'
    }
    

    See this page for an example, as well as columns.editField for reference documentation.

    Allan

  • jgessingerjgessinger Posts: 38Questions: 6Answers: 0

    Allan, you always have a solution for my problems. This is really a thoughtful finalized plugin! Thank you so much!

This discussion has been closed.