vitalets / x-editable

In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
http://vitalets.github.io/x-editable
MIT License
6.51k stars 1.72k forks source link

How to set PK? #999

Closed Trimakas closed 7 years ago

Trimakas commented 7 years ago

For the life of me I can't seem to set the PK field. Everything else is perfect, but I need to set that field in order to pull the ID I need.

I just provide a JSON object with all the correct field names that align with my table. I'm trying the same with the data-pk field but it doesn't want to work.

Thanks Todd

MarQuisKnox commented 7 years ago

Docs: http://vitalets.github.io/x-editable/docs.html

marctonon commented 6 years ago

@Trimakas I had the same problem, because I am using X-editable as a plugin for wenzhixin \ Bootstrap table (https://github.com/wenzhixin/bootstrap-table).

To solve our problem, we have to initialize our table using the tag data-id-field="\<put your pk field name from JSON here>" as part of \<table> tag.

Example:

                    <table id="table"
                           data-id-field="id"
                           data-toggle="table"
                           data-pagination="true"
                           data-show-export="true"
                           data-url="/testemetas/2017/12"
                           data-show-refresh="true"
                           data-show-columns="true"
                           data-search="true"
                           data-query-params="queryParams"
                           data-toolbar="#toolbar">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="descrNomeLoja" data-editable="false">Loja</th>
                            <th data-field="descrNomeIndicador" data-editable="false">Indicador</th>
                            <th data-field="nm_valor" data-editable="true">Meta</th>
                        </tr>
                        </thead>
                    </table>

I hope this help other people looking for the same issue.

Best regards.