拖放事件后如何获取行号?

时间:2018-07-30 18:51:33

标签: javascript free-jqgrid

我需要发送删除元素和行的行号作为请求的一部分。例如,请参见下图和以下示例:

enter image description here

Ex1:

  • 重新排序行ID 338932 ,并将其移至第一位置

预期输出:

[
  {
    "id": 338932,
    "field_seq": 4,
    "row": 1
  }
]

Ex2:

  • 重新排序行ID 338932 ,并将其移至第三位

预期输出:

[
  {
    "id": 338932,
    "field_seq": 4,
    "row": 3
  }
]

我一直在玩,但是我无法正常工作。请参见下面的代码:

questions.jqGrid({
    url: sessionStorage.getItem('site_url') + 'ajax/questions/get/' + form_id,
    datatype: 'json',
    colNames: ['id', 'grid_id', 'seq', 'type', 'text'],
    colModel: [
        {name: 'field_id', index: 'id', width: 100, editable: false, search: false},
        {name: 'grid_id', index: 'grid_id', width: 50, editable: false, search: false},
        {name: 'field_seq', index: 'seq', width: 45, editable: false, search: false},
        {name: 'type', index: 'type', width: 125, editable: false, search: false},
        {name: 'field_name', index: 'text', width: 585, search: false}
    ],
    autowidth: true,
    rowNum: 200,
    cmTemplate: {width: 300, autoResizable: true},
    iconSet: 'fontAwesome',
    guiStyle: 'bootstrap',
    autoResizing: {compact: true, resetWidthOrg: true},
    viewrecords: true,
    autoencode: true,
    sortable: true,
    pager: true,
    toppager: true,
    hoverrows: true,
    multiselect: true,
    multiPageSelection: false,
    rownumbers: true,
    loadonce: true,
    autoresizeOnLoad: true,
    forceClientSorting: true,
    ignoreCase: true,
    prmNames: {id: 'field_id'},
    jsonReader: {id: 'field_id'},
    localReader: {id: 'field_id'},
    navOptions: {edit: false, add: false, search: false, del: false, refresh: true},
    pgbuttons: false,
    pginput: false,
    caption: 'Questions',
    height: 100,
    editurl: sessionStorage.getItem('site_url') + 'ajax/questions/edit',
    beforeSelectRow:
    handleMultiSelect,
    onSelectRow: function (ids) {
        if (ids !== null) {
            $('#option_field_id').val(ids)
            $('.field_seq_section').hide()

            $.ajax({
                type: 'POST',
                url: sessionStorage.getItem('site_url') + 'ajax/questions/get_grid_example/' + ids,
                success: function (msg) {
                    if (msg !== '') {
                        $('#options_ids').empty()
                    }

                    $('#grid_cells_example').html(msg)
                }
            })

            edit_question(sessionStorage.getItem('site_url') + 'ajax/questions/get_by_id/' + ids, false)
        }
    },
    loadComplete: function () {
        var $self = $(this), p = $self.jqGrid('getGridParam'),
          seq_number = this.rows.length

        $('#next_seq_num').val(seq_number)
        $('#field_seq').empty()
        $('#grid_field_seq').empty()
        for (var i = 1; i <= seq_number; i++) {
            var sel = (i == seq_number) ? 'selected' : null
            $('#field_seq').append('<option ' + sel + '>' + i + '</option>')
            $('#grid_field_seq').append('<option ' + sel + '>' + i + '</option>')
        }

        $(window).trigger('resize');
    }
})
  .jqGrid('hideCol', 'cb')
  .jqGrid('sortableRows', {
      update: function (e, ui) {
          var selectedRowId = questions.jqGrid('getGridParam', 'selrow')
          var cellValue = questions.jqGrid('getCell', selectedRowId, 'field_seq')

          console.log(selectedRowId)
          console.log(cellValue)

          resequence_questions(site_url)
          questions.trigger('reloadGrid', {fromServer: true})
      }
  })
  .jqGrid('navGrid', {
      reloadGridOptions: {fromServer: true}
  });

在上面的代码中,以下几行的行为如下:

console.log(selectedRowId) // null
console.log(cellValue)     // false

我缺少什么?我该如何实现?我正在使用free jQgrid 4.15.4-pre

0 个答案:

没有答案