How to merge rows and update some columns based on a dropdown in one column?

How to merge rows and update some columns based on a dropdown in one column?

krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0

Hi everyone!

I want to create a table like this:

The values of the last three columns should change based on the item I select from the dropdown.

I have two web services.

The first web service returns me the entire data and the second web service returns me values for Authorization resource column. I have to merge rows with same nid and the option selected selected from dropdown menu should update the last three keys columns. How should I do this?

Here is a sample ajax data

Service 1:
{
"authz_int": [
{
"id": 2,
"nid": "brett.lee",
"wsuid": 766564232
"name": "lee, brett",
"authz_resource_name": "comp_bal",
"key_1": 15,
"key_2": 5,
"key_3": 6

},
{
  "id": 3,
  "nid": "brett.lee",
  "wsuid": 766564232
  "name": "lee, brett",
  "authz_resource_name": "authz_exp",
  "key_1": 25,
  "key_2": 10,
  "key_3": null,
},
{
  "id": 4,
  "nid": "brett.lee",
  "wsuid": 766564232
  "name": "lee, brett",
  "authz_resource_name": "super_map",
  "key_1": null,
  "key_2": null
  "key_3": null,
},
{
  "id": 5,
  "nid": "shaun.tait",
  "wsuid": 123456789
  "name": "tait, shaun",
  "authz_resource_name": "comp_bal",
  "key_1": 15,
  "key_2": 5,
  "key_3": 6

},
{
  "id": 6,
  "nid": "shaun.tait",
  "wsuid": 123456789
  "name": "tait, shaun",
  "authz_resource_name": "authz_exp",
  "key_1": 25,
  "key_2": 10,
  "key_3": null,
},
{
  "id": 7,
  "nid": "shaun.tait",
  "wsuid": 123456789
  "name": "tait, shaun",
  "authz_resource_name": "super_map",
  "key_1": null,
  "key_2": null
  "key_3": null,
},

]
}

**Service 2:
**
{
"authz_resource" : [
{
"name": "comp_bal",
"description": "Compensatory Balances"
},
{
"name": "authz_exp",
"description": "Authorization Manager"
},
{
"name": "super_map",
"description": "Supervisor Position Mapping"
}
]
}

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @krupal.jadhav ,

    I don't understand when you say the last three columns are based on the resource selection, since all the data is returned from that first service - the second service just maps the name ID to a description string?

    But, what I would expect, is that the second service just stores the values in an array for the resources, then the first service creates the table using that array to populate the resource column.

    Cheers,

    Colin

  • krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0

    Hi @colin ,

    Yes the second service just maps resource name to resource description. What I want to do is, I want to update last three columns based on my dropdown selection.

    For example consider this, my service returns following data:

    John, 12345, Supervisor Mapping, 25, 0, 2
    John, 12345, Comp Balance, 100, 1, 26
    John, 12345, Authorization, 85, 9 ,81
    Mark, 4578, Supervisor Mapping, 96, 35, 6
    Mark, 4578, Comp Balance, 71, 2, 34
    Mark, 4578, Authorization, 89, 66, 7

    So the final output in my datatables should only be 2 rows:

    John, 12345
    Mark, 4578

    The third column should be a dropdown containing 3 options: Supervisor Mapping, Comp Balance, Authorization

    And my last three columns should be updated based on option which I choose from the dropdown.

    How Should I do this?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    While this example is not exactly what you describe maybe it will help you get started:
    http://live.datatables.net/yogayixa/1/edit

    Kevin

This discussion has been closed.