G
G
GrimJack2017-08-11 18:11:11
JavaScript
GrimJack, 2017-08-11 18:11:11

How to correctly display columns in datatables in angular?

The server returns such data ZHMYAK
A small explanation:
The first three objects (there can be any number of them and can be called absolutely randomly) are the fields themselves (cell). Inside each there is its width, the data of the cell itself and where to refer when clicked (link_to).
There is also record_id and linked_record_id, they are needed for link_to. Roughly speaking, it will be necessary to redirect the user to the address link_to/record_id (or linked_record_id depends on the conditions for a particular link_to) on click.
Actually, the question is how to arrange the output of this data on the front through the datatable on angular 1.
I’m not good with js, and it’s even worse with angular, so I ask you to poke your nose at the right part of the documentation. It may need to be rebuilt.
Previously it was like this:

$('.js-datatable').dataTable({
            'processing': true,
            'ajax': '/desktop/api/lookups/',
            'columns': [
                {
                    data: 'job_address',
                    "width": "50%",
                    "createdCell": function (td, cellData, data, row, col) {
                        $(td)
                            .attr('data-record_id', data.record_id)
                            .on('click', function () {
                                $state.go('job-addresses.item', {record_id: $(this).data('record_id')});
                            });
                    }
                },
                {
                    data: 'customer_name',
                    "width": "40%",
                    "createdCell": function (td, cellData, data, row, col) {
                        $(td)
                            .attr('data-linked_record_id', data.linked_record_id)
                            .on('click', function () {
                                $state.go('customers.item', {record_id: $(this).data('linked_record_id')});
                            });
                    }
                },
                {
                    data: 'updated_at',
                    "width": "10%"
                }
            ]
        });

Now we need to revise the logic of work, because. each request has its own fields and keeping separate views for this is not profitable. So the question is, how to correctly draw the output of this data?
I ask you not to kick much, I haven’t learned how to use Google for js tasks yet.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question