0

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

Community
  • 1
  • 1
Pouya
  • 1,853
  • 16
  • 53
  • 78
  • Where you defined `localstr` variable? You use `+=` operation with `localstr`. What is initial value of `localstr`? `undefined`? You call `editRow` **for every row** of the grid in `loadComplete`. Why you do this? It make the filling of the grid much slowly. Typically one call `editRow` inside of `onSelectRow`. It speeds up and simplifies everithing. Additionally you use `navGrid` with `edit: true` which enable you *form editing* additionally to *inline editing*. Which editing mode you want to use? – Oleg Jun 27 '12 at 08:11
  • @ oleg: in value localstr is 2:Dolar;3:Pond;4:Rial. i want when form load if coulmn editable is true change to editable. i don't understant this- Additionally you use navGrid with edit: true which enable you form editing additionally to inline editing. Which editing mode you want to use?- – Pouya Jun 27 '12 at 08:28
  • It's important to know the data which you fill in the `'CURRENCY_ID'` column. It should be values like `2`, `3` or `4` and not the texts `Dolar`, `Pond` or `Rial`. There are no the best editing mode. Sometime I use form editing sometime inline editing, but the usage of both modes like you do this makes more problems. You wrote: "i want when form load if coulmn editable is true change to editable." You mean probably that you want to start editing of all rows, but I don't understand the reason of that. I would start editing of *one* row if the user select the row and then save *the row* changes. – Oleg Jun 27 '12 at 08:46
  • @ oleg : i have a form for data entry. i load all COST_NAME and i want user enter AmontCost and CurrencyType after that click in save button so i change all row to editable in start, please if this solution is not true, please give me a solution, thanks mr oleg for help me. – Pouya Jun 27 '12 at 09:43
  • I suppose you mean that you have "a form for data entry" additionally to the code which you posted. Because I don't know exactly your requirements it's difficult to recommend you something. Nevertheless the call of `editRow` for *selected* row only in `onSelectRow` callback seems me still better as calling of `editRow` in the loop for *all* rows. About your main question with no dropdown list for `CURRENCY_ID` I think that *the filling* of jqGrid with data could be origin of the error. You should append your question with the JSON response from the server. – Oleg Jun 27 '12 at 10:24
  • @ Oleg: i Edit Post, thanks for help me. – Pouya Jun 27 '12 at 10:48
  • Could you post the same JSON data as text? – Oleg Jun 27 '12 at 11:09

1 Answers1

1

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.

Oleg
  • 217,934
  • 30
  • 386
  • 757
  • @mohsen: could you post text instead of the pictures? Moreover I still don't find any values for `'CURRENCY_ID'` in the JSON and the number of column in JSON (8) still don't corresponds to the number of columns in the `colModel` (7). The values in JSON for the `'CURRENCY_ID'` must be 2, 3 or 4 to corresponds to `editoptions.value` (`"2:Dolar;3:Pond;4:Rial"`) which you use in the code. – Oleg Jun 27 '12 at 11:42