moja
moja

Reputation: 95

Adding JSON object-related link to Dynatable rows

I am trying out Dynatables and, so far, I am able to display my data correctly and update its contents when a certain event happens. So far, this is what I have: http://jsfiddle.net/pDVvx/28/

$(document).ready( function() {
  var allSales = [{
    locationId: 1001,
    location: "Store A",
    item: "Soap",
    quantity: 2,
    amount: 99.50
  },{
    locationId: 1002,
    location: "Store B",
    item: "Tissue",
    quantity: 1,
    amount: 49.75
  }];

  var allSales2 = [{
    locationId: 2001,
    location: "Store C",
    item: "Bag",
    quantity: 1,
    amount: 10000.00
  },{
    locationId: 2002,
    location: "Store D",
    item: "Shoe",
    quantity: 2,
    amount: 5999.50
  }];

  var locationDetails = [{
    locationId: 1001,
    location: "Store A",
    address: "some address here",
    manager: "Pepito Manaloto"
  },{
    ....
  }];

  var updateDynaTable = function(argument){
    console.log("argument for updateDynaTable");
    console.log(argument);
    dynatable.settings.dataset.originalRecords = argument;
    dynatable.process();
  }

  var dynatable = $('#my-final-table').dynatable({
    dataset: {
        records: allSales
    }
  }).data('dynatable');

  $("#button1").click(function(){
    updateDynaTable(allSales);  
  })

  $("#button2").click(function(){
    updateDynaTable(allSales2);  
  })
});

Furthermore, I want to make each location (Store A, Store B, etc.) a clickable link with the respective locationID associated with it. I need this so that whenever I click a store link, the corresponding store details (as shown in locationDetails table) will be prompted.

For example, if sales1 button is clicked and Store A is also clicked, a prompt (could be an alert) will show the store's address and manager (from locationDetails table).

If anyone can suggest any solution, that would be very helpful. Thank you!

Upvotes: 1

Views: 659

Answers (1)

Steve Wollkind
Steve Wollkind

Reputation: 61

I've been looking at this for the past 20 minutes or so and I'm coming to the conclusion that this is not going to be easy if you build your dynatable from JSON. I think that the countries example at the top of the dynatable site is probably built as a regular html table on the server side and then dynatable is just being used for sorting/pagination/etc.

Seems like the other likely option would be to return, in your JSON, the full content of the cells you want to create, including any links, etc (or postprocess the JSON in javascript to mangle it into the form you want).

Upvotes: 1

Related Questions