Using Editor to populate datatable row from external table on selection of items

Using Editor to populate datatable row from external table on selection of items

bhandaribishnubhandaribishnu Posts: 9Questions: 4Answers: 1
edited March 2016 in Free community support

I have following tables .
Table 1: ItemMaster Columns : ItemID, ItemName, Price,PackSize
Table 2 : OrderDetails Columns: OrderId, ItemID, ItemName, Price,PackSize

I want suggestion on handling this problem,

On OrderDetails Datatable,
Whenever I change ItemName ,it should pull information Price, PackSize from ItemMaster Table and populate to the OrderDetails Datatable. so I can edit or save as it is to the OrderDetails Table.

Suggest me , how to populate the row selected columns the json data received.

NOTE: I tried to use

editor.on( 'preSubmit', function ( e, obj, callback )
 if(action='edit'){
                                             var desc = editor.field( 'orderdetails.ItemName' ).val();
                                              alert(desc);
                                                $.ajax( {
                                                             url: 'itemdetails.php',
                                                             data: {
                                                                    ItemName: desc
                                                                           },
                                                             dataType: 'JSON',
                                                             success: function ( json ) {
......



});


I have created OrderDetails Datatable :

(function($){

$(document).ready(function() {
                           
    var editor = new $.fn.dataTable.Editor( {
        ajax: 'OrderDetails.php',
        table: '#orderdetails',
        fields: [
            {
                "label": "ItemID",
                "name": "OrderDetails.ItemID"
            },
            {
                "label": "ItemName",
                "name": "OrderDetails.ItemName",
                 type: "select"
                
            },
{
                "label": "Price",
                "name": "OrderDetails.Price",
                            
            },
{
                "label": "PackSize",
                "name": "OrderDetails.PackSize",
                            
            },
......


    var table = $('#')orderdetails.DataTable( {
        dom: 'Bfrtip',
        ajax: 'php/table.proformaitems.php',
        columns: [
            {
                "data": "OrderDetails.itemID"
            },
            {
                "data": "OrderDetails.ItemName"
            },
            {
                "data": "OrderDetails.PackSize"....

Answers

  • allanallan Posts: 61,823Questions: 1Answers: 10,129 Site admin

    I'm actually planning on writing a detailed blog post on exactly this topic this afternoon. Keep an eye on the blog for when it becomes available.

    Regards,
    Allan

  • bhandaribishnubhandaribishnu Posts: 9Questions: 4Answers: 1

    Allan, Eagerly Waiting for that .
    Regards,
    Bishnu

  • allanallan Posts: 61,823Questions: 1Answers: 10,129 Site admin

    Published now :-)

    Allan

  • bhandaribishnubhandaribishnu Posts: 9Questions: 4Answers: 1

    Thanks you saved my Month !! i had been scratching my head a lot !!:)

This discussion has been closed.