angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

DTColumnbuilder nested object?

Open p-rez opened this issue 10 years ago • 5 comments

I hope this is the right place to ask this question but i simply don't know if it's possible to display a specific nested object with angular datatables.

I'm doing a part catalog with server side processing, 1 part can have many part numbers, so what i want to do is to have 2 columns;

1 displays the description, and the other displays the first part number

Let me show you my response; datable

This is how i did my server request, this one gives me the entire object of parts and the parts number associated with that part screenshot from 2016-06-28 17 00 07

And this is how i thought i could do the other column that displays the first part number, but it seems like is not working screenshot from 2016-06-28 17 00 24

My question is, is there a way to get the first value of a nested object through DTColumnbuilder? or is there another way i can aproach this problem?

Sorry if this is not the place to ask such things but i didnt find anything about this on angular datatables API documentation. Cheers.

p-rez avatar Jun 29 '16 00:06 p-rez

Sorry, any ideas? Is there a way to make a column that displays the first element of a nested object through dtcolumnbuilder?

p-rez avatar Jul 01 '16 19:07 p-rez

Your data is something like this:

{
  "data": [{
    "description": "0 part",
    "id": 29,
    "parts_number": [{
      "id": 40,
      "part_number": 29,
    }]
  }]
}

If you want to access to the part_number value, then you need to define your columns like this:

$scope.dtColumns = [
  DTColumnBuilder.newColumn('parts_number[0]part_number').withTitle('Part number'),
  DTColumnBuilder.newColumn('description').withTitle('Description')
];

l-lin avatar Jul 01 '16 20:07 l-lin

Thanks so much for looking at my question Unfortunately it's not working (for now), i did as you say and the moment i enter to the page i get this message: data1

After pressing 'Ok' the rest of the table loads up normally except for the new column, which displays nothing: data2 code:

$scope.dtColumns = [
DTColumnBuilder.newColumn('description').withTitle('Part description'),
DTColumnBuilder.newColumn('parts_number[0]part_number').withTitle('1st part number'),
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)


];

BUT if i don't specify which value i want to display i got something like this: data3

code:

$scope.dtColumns = [
DTColumnBuilder.newColumn('description').withTitle('Part description'),
DTColumnBuilder.newColumn('parts_number[0]').withTitle('1st part number'),
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)


];

I don't know what's causing this, maybe i'm overlooking something?

p-rez avatar Jul 01 '16 22:07 p-rez

My bad, it should be parts_number[0].part_number.

l-lin avatar Jul 01 '16 22:07 l-lin

Welp i found a workaround by just using points "." like this =

$scope.dtColumns = [ DTColumnBuilder.newColumn('parts_number.0.part_number').withTitle('1st part number'), ];

And it works too if i do it like you just have said. Thanks a lot for your help.

p-rez avatar Jul 01 '16 22:07 p-rez