Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82801

How to

$
0
0
Greetings,
I am having an issue when attempting to produce a dropdown list from a JSON object data. The JSON object is built using MVC and passed to DT via sAjaxsource call to Controller method.(pl note not using bServerSide=true, and do not want to!)

Scenario is that I have a list of records containing manufacturer product details, and each record should contain a list of products supplied by that manufacturer, with the currently selected product shown as the selected option - a reasonably simple use case I guess?

I am successfully able to retreive a list of Manufacturer details from the database as a JSON object that happily renders onto a DT when rendering text items :http://live.datatables.net/unator/12/edit#javascript,html,live. however unable to figure out how to add a DD field to this.

My starting point is to mock up the JSON as a JS variable, and then figure out how to render this as a dropdown using mRender as per advice provided to me in an earlier post.

However this is coming unstuck as am unable to figure out the correct format for rendering a list of items in the JSON array.

As per one of the examples on the net, an acceptable JSON string for a select list of products and IDs is as follows :
[
[ "1","ProductName1"],
[ "2", "ProductName2"],
["3","ProductName3"]
]

however would this be valid for returning a list of products to DT, for a JSON object source? I am not sure about this since as per the documentation and this article - (http://www.codeproject.com/Articles/194916/Enhancing-HTML-tables-using-a-JQuery-DataTables-pl), the accepted format when using JSON as objects, is stated to be {"PropertyName":"Value"}? - indeed this is how I have rendered the JSON w/out the select list items and it works fine.

mock of JSON attempted so far - does not validate in JSON lint and I am unable to figure out how to reformat to validate
           {"DataRecordId":"1", "ProductVolume":"10.00", "ProductCode":"ABC.DEF.DDD.001",
           "ProductList":["ProductId":"1","ProductName":"Product1"],["ProductId":"2","ProductName":"Product2"]}


so need some help in understanding what precise JSON format is expected for select list items and then how to render these using
mRender?
Have looked high low on the internet and on these forums for a simple example/explanation for this, but unsuccessful.

Just FYI There are other functionalities dependent on this such as linking other table content to selected option value, validation, editing etc

Thanks
kG

Viewing all articles
Browse latest Browse all 82801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>