使用 jQuery [关闭]选择网格行

问题描述 投票:0回答:0

我是jQuery的新手,我有这段代码,它组装了一个网格,我需要添加一个按钮来重新处理(将数据发送到服务器),模态内的按钮已经可以了,但是在加载页面时并选择要发送的一行网格,它将始终是已选择行的数据,除非我重新加载页面并选择另一行。

我想捕获在网格上单击的行的数据,而无需重新加载页面。


$("#MovimentoDiarioGrid").jqGrid('navButtonAdd',
  '#MovimentoDiarioGridPager', {
    id: 'btReprocessar',
    caption: '',
    title: 'Reprocesar Arquivo',
    buttonicon: "ui-icon-arrowreturnthick-1-n",
    onClickButton: openReprocessModal,
    position: "last",
  });
$('body').append('<div id="reprocess-modal" title="Reprocessar Arquivo" style="display:none;"></div>');
$('#reprocess-modal').dialog({
  autoOpen: false,
  modal: true,
  buttons: {
    "Reprocessar": openReprocessModal,
    "Fechar": function() {
      $(this).dialog("close")
    }
  }
});

function openReprocessModal() {
  var grid = $("#MovimentoDiarioGrid");

  if (grid.jqGrid('getGridParam', 'selrow') === null) {
    $('#reprocess-modal').html('Por favor, selecione um registro.');
    $('#reprocess-modal').parent().find('button:contains("Reprocessar")').hide();
    $('#reprocess-modal').parent().find('button:contains("Fechar")').hide();
    $('#reprocess-modal').dialog('option', 'title', 'Aviso');
    $('#reprocess-modal').dialog('open');
    return;
  }

  var status = '',
    resProcessamento = '',
    idArquivo = '',
    idInstituicao = '',
    idCtlProcessamento = '',
    numCtrlCcs = '';

  var rowData = $("#MovimentoDiarioGrid").jqGrid('getRowData', selectedRow);
  var status = rowData.Status;
  var resProcessamento = rowData.ResultadoProcesso;
  var idArquivo = rowData.IdArquivo;
  var idInstituicao = rowData.IdInstituicao;
  var idCtlProcessamento = rowData.IdControleProcessamento;
  var numCtrlCcs = rowData.NrCtrlCcs;

  if (status === '<span class="ui-icon ui-icon-check"></span>') {
    $('#reprocess-modal').parent().find('button:contains("Reprocessar")').hide();
    $('#reprocess-modal').html(resProcessamento + ' Não há necessidade de reprocessar o arquivo.');
  } else if (resProcessamento === 'Aguardando reprocessamento') {
    $('#reprocess-modal').parent().find('button:contains("Reprocessar")').hide();
    $('#reprocess-modal').html(resProcessamento);
  } else {
    $('#reprocess-modal').parent().find('button:contains("Reprocessar")').show();
    $('#reprocess-modal').html('Ao processar este arquivo, ocorreu o seguinte erro: ' + resProcessamento + ' Caso esse erro já tenha sido solucionado clique em Reprocessar.');
  }

  $('#reprocess-modal').dialog('open');

  $('#reprocess-modal').parent().find('button:contains("Reprocessar")').on('click', function() {
    $.ajax({
      url: '<%= ResolveClientUrl("~/UserControls/MovimentoDiarioGridUCHandler.ashx") %>',
      data: {
        ActionPage: 'TransportType',
        Action: 'ReprocessarArquivo',
        IdArquivo: idArquivo,
        IdInstituicao: idInstituicao,
        IdControleProcessamento: idCtlProcessamento,
        NrCtrlCcs: numCtrlCcs
      },
      type: 'POST',
      dataType: 'json',
      success: function(response) {
        $('#reprocess-modal').dialog('close')
      },
      error: function(xhr, textStatus, errorThrown) {
        console.error('Erro:', textStatus, errorThrown)
      },

    });
  });

}
openReprocessModal();
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css" integrity="sha512-iPBveaEDzIhTkkNUneoCsHyv+N7We/akyLzZjgBn8VIup/ke6IQzgmHoAsnJFk+CGM/D3d3ci8/pyme8IXPEhw==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.min.js" integrity="sha512-DpikOGsrn8/5VLiM0t6fhHHWovOIqaIIq4wcpkl/TKFM4naa03uaEZ23sYcamFiOx1b5L1pYsUwRjTQN62Eohg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<div>Please help I need HTML! maybe more?</div>
<div id="MovimentoDiarioGridPager"></div>

jquery asp.net jquery-ui jqgrid
© www.soinside.com 2019 - 2024. All rights reserved.