This is a migrated thread and some comments may be shown as answers.

Simple solution but escapes me

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 17 Jan 2014, 04:26 PM
I have inherited some code to fix what should have been a validation issue. I believe the best fix would be to change the field type in the grid to be a dropdown. At issue is changing the field to a drop down. As seen below, the last developer is creating a grid through JavaScript. This function is called from another JavaScript function which was called from an change event of another grid. Below is the code from the two involved scripts. I have attached a file containing all the other pertinent files to draw conclusions of the functionality that is in place. I want to replace the field "EXPLANATION_CODE" near below with a drop down sourced from a database table but still bounded as it is currently. I would think this should be rather simple but is beyond my current understanding. Also, I am not authorized to change how the grid is currently coded. So I cannot remove it from the function and place it in the view. I can only change the type of the field. Any and all help would be greatly appreciated. If after reviewing the functionality, you see a better way to perform all the required functionality, please forward thoughts. I may be able to refactor later to remove this hideous monstrosity.

/* Following function is in a separate script file and is called from another function */
function SendDocTranInfoToServer(pDocId, pDocSeq) {
    if ($("#kGridExplanations").data("kendoGrid") == null) {
        $("#kGridExplanations").kendoGrid({
            columns: [
                { field: "EXPLANATION_CODE", title: "Code", width: "200px" },
                { command: "destroy" }
            ],
            editable: {
                createAt: "top"
            },
            toolbar: ["create"]
        });

    } else {
        var saveExplanations = "";
        var expGrid = $("#kGridExplanations").data("kendoGrid");
        var expGridDs = $("#kGridExplanations").data("kendoGrid").dataSource;
        var allData = expGridDs.data();

        for (var i = 0; i < allData.length; i++) {
            saveExplanations = saveExplanations + allData[i].EXPLANATION_CODE + "|";
        }
        $.ajax({
            url: "/Inquiry/SetExplanationCodeAndText",
            dataType: "json",
            type: "POST",
            data: { docId: $("#hdPrevDocId").val(), docCount: $("#hdPrevDocCount").val(), expCode: saveExplanations, filingText: $("#tbTextFiling").val() },
            success: function (response) {
            }
        });
        expGrid.dataSource.data([]);
        $("#tbDocCountFiling").val("");
        $("#tbTextFiling").val("");
    }
    $("#hdPrevDocId").val(pDocId);
    $("#hdPrevDocCount").val(pDocSeq);

    var explanationCodes = [];
    $.ajax({
        url: "/Inquiry/GetExplanationCodeByCount",
        dataType: "json",
        type: "POST",
        data: { docId: pDocId, docCount: pDocSeq },
        success: function (response) {
            if (response.hasError) {
            }
            if (!response.hasError) {
                for (var i3 = 0; i3 < response.length; i3++) {
                    var explanationCode = {
                        EXPLANATION_CODE: response[i3].EXPLANATION_CODE,
DOC_COUNT: response[i3].DOC_COUNT,
                    };
                    explanationCodes.push(explanationCode);
                 }  
                 if (explanationCodes.length == 0) {
                     if ($("#kGridExplanations").data("kendoGrid") != null) {
                         $("#kGridExplanations").data("kendoGrid").dataSource.data([]);
                     }
                 } else {
                     var dsExpCode = new kendo.data.DataSource({
                         schema: {
                             model: {
                                 fields: {
                                     EXPLANATION_CODE: { type: "string" },
                                 }
                             },
                             parse: function (response) {
                                 return explanationCodes;
                             }
                        }
                    });

                    if ($("#kGridExplanations").data("kendoGrid") != null) {
                        var grid1 = $("#kGridExplanations").data("kendoGrid");
                        grid1.setDataSource(dsExpCode);
                    }
                }
            }
        }
    });
}
/* Following function from view holding a separate grid and used for the change event */
function kGrdCDocTransChange(arg) {
      var ar = arg;
     var selectedRows = this.select();
     var selectedDataItems = [];
     for (var i1 = 0; i1 < selectedRows.length; i1++) {
         var dataItem = this.dataItem(selectedRows[i1]);
         selectedDataItems.push(dataItem);
     }
     SendDocTranInfoToServer(selectedDataItems[0].DOC_ID, selectedDataItems[0].DOC_COUNT);
 }

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 21 Jan 2014, 07:17 PM
Hello,

I am not sure if I understand correctly what you mean by:
I am not authorized to change how the grid is currently coded
but the only to use a dropdownlist for the editor is to modify the code for the column. There isn't a way to specify that a dropdown should be used from the model definition and you should either use a custom editor for the column or a foreignkey column.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or