Editor display the values ​​in the select

Editor display the values ​​in the select

klermannklermann Posts: 277Questions: 67Answers: 1
edited September 2017 in Free community support

Hello Allan, how do I retrieve, to display the values ​​in the select, coming from the table that comes from the database? Because when trying to recover these values ​​my select is empty!
I'm using the select2 plugin available here!
The list of items is available, but the value is not set!
ec2-54-86-12-163.compute-1.amazonaws.com:8080/financeiro/receitas

Answers

  • klermannklermann Posts: 277Questions: 67Answers: 1
    edited September 2017

    Hello Allan, how do I retrieve, to display the values ​​in the select, coming from the table that comes from the database? Because when trying to recover these values ​​my select is empty!
    I'm using the select2 plugin available here!
    The list of items is available, but the value is not set!
    ec2-54-86-12-163.compute-1.amazonaws.com:8080/financeiro/receitas

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    I'm getting a "denied" at that link I'm afraid.

    how do I retrieve, to display the values ​​in the select, coming from the table that comes from the database?

    I don't really understand this I'm afraid. The values passed into the set plug-in function are the values that should be selected.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1
    edited September 2017
  • klermannklermann Posts: 277Questions: 67Answers: 1

    I understand this, but the values ​​are in lilsta, but does not retrieve the item when I try to edit an item, they are presented in the table, remembering that the values ​​that are retrieved from the list come individually by json in another function!

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    Yes, it appears to load for me okay now.

    I believe the problem you are having is that you are trying to select based on the label not the value.

    For example, this is the option in the Select2 list:

    <option value="0">Tipo de Receita</option>
    

    If you pass in a value of "Tipo de Receita" it won't select anything since the value is actually 0. The field is set up as tipoReceitas.nome, so I'm fairly certain this is the issue. You need to select based on the id (whatever the name of that is).

    The join documentation and example has full details about this.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1
    edited September 2017

    You tell me this is my server returning a json in this format, which is what you went through. The leftJoin () method will bring the item concerned and make a link to the electronic version. The question is where does this method use: leftJoin ().

    { "users": { "first_name": "Quynn", "last_name": "Contreras", "phone": "1-971-977-4681", "site": "1" }, "sites": { "name": "Edinburgh" } }

    Remember that you use java, and I may very well generate the output!

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    In my example we have:

    {
        "DT_RowId": "row_1",
        "users": {
            "first_name": "Quynn",
            "last_name": "Contreras",
            "phone": "1-971-977-4681",
            "site": "1"
        },
        "sites": {
            "name": "Edinburgh"
        }
    }
    

    The label (which is shown in the DataTable column) is sites.name - in this case Edinburgh.

    The value (which Editor edits) is users.site - in this case 1.

    Note that they are different property names. I don't want the select to edit the label, I want it to edit the selected value.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Hello Allan, make an implementation that asked me and I did not get the expected result, which seems to take a look please?
    ec2-54-86-12-163.compute-1.amazonaws.com:8080/financeiro/receitas/

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Hello Allan I followed all your guidance, but not for sure, for me what is difficult is a list that fills the select comes from a different json, and now I presented the field in the table as directed but not presented in the select! What to do?

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    In the DataTable you are showing:

    data: "tipoReceitas[0].nome"
    

    I'm not sure why it is an array of data, but it appears to be so.

    In the Editor you have:

    name: 'tipoReceitas.nome',
    

    So the first issue is that DataTables is working with an array, while Editor is using an object.

    The second issue is that presumably you don't actually want to edit tipoReceitas.nome you want to edit something that points to that. What is the column name you want to edit?

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I'm trying to first a column like "conta"..

  • klermannklermann Posts: 277Questions: 67Answers: 1

    In editor
    { name: 'minhasContas.nome', "type": "select2", "ipOpts": lists(), "opts": { "placeholder": "Selecione uma conta ...", "allowClear": true } },

    and table

    { data: "mContas" },

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I am using the select2 plugin ...

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    Its the same issue as we've discussed before.

    The data source object for the row looks like this:

    {
        "id": 1,
        "descricaoReceita": "Receita 1",
        "dataReceita": {
            "year": 2017,
            "month": "AUGUST",
            "chronology": {
                "calendarType": "iso8601",
                "id": "ISO"
            },
            "monthValue": 8,
            "dayOfMonth": 29,
            "dayOfWeek": "TUESDAY",
            "era": "CE",
            "dayOfYear": 241,
            "leapYear": false
        },
        "valorReceita": 5000.00,
        "receitaFixa": false,
        "receitaFixaQuantidade": 0,
        "receitaFixaTempo": null,
        "repetirLancReceita": false,
        "repetirPorPeriodo": null,
        "pagamento": true,
        "addObservacao": null,
        "tipoReceitas": [{
            "id": 1,
            "nome": "Tipo de Receita",
            "corTipoReceita": "#232322",
            "nomeTipoReceita": "Tipo de Receita"
        }],
        "minhasContas": [{
            "id": 1,
            "nome": "Contas1",
            "dataAcesso": {
                "year": 2017,
                "month": "AUGUST",
                "chronology": {
                    "calendarType": "iso8601",
                    "id": "ISO"
                },
                "monthValue": 8,
                "dayOfMonth": 8,
                "dayOfWeek": "TUESDAY",
                "era": "CE",
                "dayOfYear": 220,
                "leapYear": false
            },
            "saldoAnterior": 1000.00,
            "saldoAtual": 2000.00,
            "saldoFinal": 3000.00,
            "tipo": "POUPANCA",
            "cor": "#ccc",
            "dashBoard": true
        }],
        "mContas": "Contas2",
        "etiquetas": [{
            "id": 1,
            "nome": "Etiqueta 1"
        }],
        "cor": null
    }
    

    The Editor configuration is:

    name: 'minhasContas.nome'
    

    And the list of options for the Select2 list is:

    [{
        "label": "Contas1",
        "value": "0"
    }, {
        "label": "Contas3",
        "value": "1"
    }, {
        "label": "Contas4",
        "value": "2"
    }, {
        "label": "Contas2",
        "value": "3"
    }]
    

    The values are numbers. The minhasContas.nome property doesn't actually exist (minhasContas is an array). And even if it did correctly select the name, that would pick Contas1 not the number!

    The value needs to reflect what you are editing. Not the label.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I do not quite understand what you mean, what do I actually change? Is the configuration or the JSON file? How should I stay in my file? An example please!

  • klermannklermann Posts: 277Questions: 67Answers: 1

    And remembering that to create or edit the data comes from two JSON files, the main one and the one that fills the list

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    An example please!

    There is an example showing how to do a join here.

    I would actually suggest that you remove Select2 and just use a select until you get this working.

    There are two points:

    1. The minhasContas.nome property doesn't actually exist in your data object.
    2. The value you appear to be trying to pass to Editor is the label - not the value.

    Note how in my example the users.site field is the one that is edited, but sites.name is the one that is displayed in the DataTable.

    Allan

This discussion has been closed.