Pouya
Pouya

Reputation: 1918

how to access to dropdownlist into jqgrid and get value

hi all i have jqgrid and set update inline . i wrote this code

 $(function () {

         var  localstr="2:Dolar;3:Pond;4:Rial";

 var rows;
            var lastSel;
            var grid = $('#list');



            grid.jqGrid({
                url: 'jQGridHandler.ashx',

                postData: { ActionPage: 'ClearanceCost', Action: 'Fill' },
                ajaxGridOptions: { cache: false },
                loadonce: true,
                direction: "rtl",

                datatype: 'json',
                height: 490,
                colNames: ['RequestId', 'WaybillNo', 'CostId', 'NameCost', 'Amount', 'CurrencyTypeId ', 'Remark'],
                colModel: [
                        { name: 'REQUEST_ID', width: 100, sortable: true, hidden: true },
                        { name: 'WAYBILL_NO', width: 100, sortable: true, hidden: true },
                        { name: 'COST_ID', width: 200, sortable: true, hidden: true },
                        { name: 'COST_NAME', width: 200, sortable: true },
                        { name: 'COST_AMOUNT', width: 100, sortable: true, editable: true },
                        { name: 'CURRENCY_ID', width: 100, sortable: true, editable: true, edittype: 'select', formatter: 'select', editoptions: {
                            value: localstr
                            //,



                        },
                        { name: 'REMARK', width: 200, sortable: true, editable: true }
                       ],

                gridview: true,
                rowNum: 30,
                rowList: [30, 60, 90],
                pager: '#pager',
                sortname: 'REQUEST_ID',
                viewrecords: true,
                sortorder: 'ASC',

                rownumbers: true,
                loadComplete: function () {

                    var $this = $(this);
                    rows = this.rows;
                    var l = rows.length, i, row;

                    for (i = 0; i < l; i++) {
                        row = rows[i];



                        var selRowId = grid.jqGrid('getGridParam', row.id);
                        console.log(selRowId);
                        console.log(grid.jqGrid('getCell', row.id, 'CURRENCY_ID'));

                        if ($.inArray('jqgrow', row.className.split(' ')) >= 0) {
                            $this.jqGrid('editRow', row.id, true);
                        }

                    }
                },
                editurl: "jQGridHandler.ashx"

            });
            grid.jqGrid('navGrid', '#pager', { add: true, edit: true, del: true }, {}, {}, {}, { multipleSearch: true, overlay: false, width: 460 });


            $("#btnsave").click(function () {
                var l = rows.length, i, row;

                for (i = 1; i < l; i++) {
                    row = rows[i];

//                    var $this = grid.jqGrid('getCell', row.id, 'COST_AMOUNT');
//                    var $id = $($this).attr("id");
//                    var COST_AMOUNT = $("#" + $id).val();


//                    console.log(grid.jqGrid('getCell', row.id, 'COST_ID'));
//                    $this = grid.jqGrid('getCell', row.id, 'COST_ID');
//                    $id = $($this).attr("id");
//                    var COST_ID = $("#" + $id).val();

                   alert(grid.jqGrid('getCell', row.id, 'CURRENCY_ID'));
//                    $this = grid.jqGrid('getCell', row.id, 'CURRENCY_ID');
//                    $id = $($this).attr("id");
//                    var CURRENCY_ID = $("#" + $id).val();

//                    $this = grid.jqGrid('getCell', row.id, 'REMARK');
//                    $id = $($this).attr("id");
//                    var REMARK = $("#" + $id).val();

//                    console.log(COST_ID + ",  " + COST_AMOUNT + ",  " + CURRENCY_ID + ",  " + REMARK);



                }

            });

        });

i want get CURRENCY_ID drop down list value when user clicked in btn, please help me. thanks all

EDIT01:

enter image description here

Mr Oleg i want design like this posted

thanks for help me

Upvotes: 0

Views: 3026

Answers (1)

Oleg
Oleg

Reputation: 221997

One can see that you use wrong order of the columns in JSON data. The text like "EURO" are in the third column, but you have the column in the grid in the 6-th place. One have to count all hidden columns too. Perhaps you need just change the order of the columns and move 'WAYBILL_NO' and 'COST_ID' in another place in colModel.

Probably it was the error which you have?

Additionally you should not forget to define all variables which you use. For example the lines

var $this = $(this);
rows = this.rows;

should be fixed to

var $this = $(this),
    rows = this.rows;

which is the same as

var $this = $(this), rows = this.rows;

The current code do

var $this = $(this);
window.rows = this.rows;

or produce an error in strict mode of JavaScript.

Upvotes: 1

Related Questions