update id in table from dropdown list

update id in table from dropdown list

omerabbasi78omerabbasi78 Posts: 17Questions: 7Answers: 1
edited August 2017 in Free community support
 table: "#tblIncomeCashFlow",
        fields: [
            {
                label: "Category Name:",
                name: "IncomeCategoryName",
                type: "select",
                ipOpts: getIncomeCategoryList(),
            },
] });
var tableincome = $("#tblIncomeCashFlow").DataTable({
        dom: "Bfrtip",
        ajax: "/api/GetCFIncomeSummary/9",

        columns: [
            { data: "IncomeCategoryName", className: "tab-1" },
]});

this just binds the dropdown on ajax call

 function getIncomeCategoryList() {
    try {
        var URL = "/Ajax/IncomeCategoryDDL";
        var SuccessLoad = function (result) {

            if (result.length > 0) {
                var aDropdownList = new Array();
                for (var i = 0; i < result.length; i++) {
                    aDropdownList[i] = {
                        "label": result[i]["IncomeCategoryName"],
                        "value": result[i]["IncomeCategoryName"]
                    };
                }
            }
            editortblIncomeCashFlow.field('IncomeCategoryName').update(aDropdownList);

        };

        var ErrorLoad = function (error) {
            alert('Please try again later.');
        };

        AjaxCall(URL, null, SuccessLoad, ErrorLoad);
    } catch (e) {

    }
}

the code above binds a dropdown in a cell and when I select option from dropdown it updates the name in table.. now what i want to do is i dont want to update name but i want to update IncomeCategoryId column in the database. When i will change the value from
"value": result[i]["IncomeCategoryName"]

to
"value": result[i]["IncomeCategoryId"]

Id will bind in value. Further what do i need to do to show the "IncomCategoryName" in dropdown but update the "IncomCategoryId" in table?

thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    It sounds like you want to use a left join. That example links to the documentation for the PHP and .NET libraries that come with Editor, and details how to use it.

    In that example you will be able to see that the location column displays the name, while it is the foreign key reference value that is updated when the form is submitted.

    Allan

  • omerabbasi78omerabbasi78 Posts: 17Questions: 7Answers: 1

    Alright Allan I've made some progress in my work by your guidance but there is a little bit of issue I'm facing after this. Dropdown shows perfectly and updation is working fine but it shows Ids on front instead of labels. Why is it so? I'm sure im doing some mistake here but can't figure it out so you might be of some help here.

    This is how im reading data

    .Field(new Field("IncomeCategoryId").DbField("Income.IncomeCategoryId").Options(new Options().Table("IncomeCategory").Value("IncomeCategory.IncomeCategoryId").Label("IncomeCategory.IncomeCategoryName")))
    

    This is how im binding

      fields: [
                {
                    label: "Income Category Id:",
                    name: "IncomeCategoryId",
                    type: "select",
                },
       ]
    
    
     var tableincome = $("#tblIncomeCashFlow").DataTable({
            ajax: "/api/GetCFIncomeSummary/@Convert.ToInt32(Request.Cookies["PropertyId"].Value)",
    
            columns: [
     { data: "IncomeCategoryId", className: "tab-1" },
    ]
     });
    
  • omerabbasi78omerabbasi78 Posts: 17Questions: 7Answers: 1

    Thanks Allan. I did it anyways ;)
    Thanks a lot

This discussion has been closed.