简体   繁体   English

使用jqgrid进行内联编辑。 我被卡住了

[英]inline editing with jqgrid. I'm stuck

here is my grid: 这是我的网格:

$("#list2").jqGrid({ 
    url:baseURL + 'contactManager/contactActivity/getActivity/' + contactsID + '/1', 
    datatype: "json", 
    colNames:['Type','Scheduled', 'Created', 'Comp','Description','Assigned To'], 
    colModel:[ 
        {name:'type',index:'type', width:55}, 
        {name:'scheduledDate',index:'scheduledDate', width:90}, 
        {name:'createdDate',index:'createdDate', width:100},
        {name:'completed',index:'completed', width:80, align:"center", sortable:true, formatter: "checkbox", formatoptions: {disabled : false}, editable: true, edittype:"checkbox"},
        {name:'description',index:'description', width:80,align:"right"}, 
        {name:'assignedID',index:'assignedID', width:150, sortable:false} 
    ], 
    rowNum:10, 
    rowList:[10,20,30],
    pager: '#pager2', 
    sortname: 'type', 
    viewrecords: true, 
    sortorder: "desc", 
    caption:"Completed" }); 

I have a checkbox with the index name "completed." 我有一个索引名称为“ completed”的复选框。 I am trying to run an ajax call when this input is edited. 编辑此输入时,我试图运行ajax调用。 I cannot get anything to fire when I touch this checkbox, not even an alert. 触摸此复选框后,我什么也无法激发,甚至没有警报。 I have tried working through the example on this page http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing but nothing is working. 我已尝试浏览此页面上的示例http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing,但是没有任何效果。 Can someone help me create a simple event handler for the checkbox? 有人可以帮我为复选框创建一个简单的事件处理程序吗?

Create a custom formatter, 创建一个自定义格式器,

Add a Class to yout check box 向您添加班级复选框

Bind change Event on document to class 将文档上的更改事件绑定到类

    jQuery(document).on("change", ".YourCheckBoxClass", function () {
    DoSomeThing(this);
});

In Your fomatter you can add attribute like Id, colName etc and can be retireved into DoSomeThing 在您的格式文件中,您可以添加Id,colName等属性,并可以重新引入到DoSomeThing中

Change {name:'completed',index:'completed', width:80, align:"center", sortable:true, formatter: "checkbox", formatoptions: {disabled : false} to {name:'completed',index:'completed', width:80, align:"center", sortable:true, formatter: "checkbox", formatoptions: {disabled : false}更改为

{name:'completed',index:'completed', width:80, align:"center", sortable:true, formatter: Mycheckbox}

function Mycheckbox(cellvalue, options, rowObject) { return '<input type="checkbox" class="YourClass" id=cb'+rowObject['rowId']+ >'; }

How about this? 这个怎么样?

$("#list2").jqGrid({ 
    url:baseURL + 'contactManager/contactActivity/getActivity/' + contactsID + '/1', 
    datatype: "json", 
    colNames:['Type','Scheduled', 'Created', 'Comp','Description','Assigned To'], 
    colModel:[ 
        {name:'type',index:'type', width:55}, 
        {name:'scheduledDate',index:'scheduledDate', width:90}, 
        {name:'createdDate',index:'createdDate', width:100},
        {name:'completed',index:'completed', width:80, align:"center", sortable:true, formatter: "checkbox", formatoptions: {disabled : false}, editable: true, edittype:"checkbox"},
        {name:'description',index:'description', width:80,align:"right"}, 
        {name:'assignedID',index:'assignedID', width:150, sortable:false} 
    ], 
    rowNum:10, 
    rowList:[10,20,30],
    pager: '#pager2', 
    sortname: 'type', 
    viewrecords: true, 
    sortorder: "desc", 
    caption:"Completed"
})
.find('input[name=completed]').bind('onchange', function() {alert('clicked')});

you can use a custom formatter to bind a function to the checkbox. 您可以使用自定义格式化程序将功能绑定到复选框。 Here are some snippets from my project where I used this method to send an ajax call to the database when the checkbox is clicked. 以下是我项目中的一些代码片段,在这些代码片段中,单击复选框后,我使用此方法将ajax调用发送到数据库。

Checkbox column definition: 复选框列定义:

{ name: 'CoreClient', index: 'CoreClient', editable: true, align: 'center', edittype: 'checkbox', formatter: checkboxFormatter, editoptions: { value: "Y:N" }, formatoptions: { disabled: false }, sortable: true}

Custom formatter function: 自定义格式器功能:

//checkboxFormatter to wire onclick event of checkbox 
  function checkboxFormatter(cval, opts, rowObj) { 
      cval = cval + ""; cval = cval.toLowerCase(); 
      var bchk = cval.search(/(false|0|no|off|n)/i) < 0 ? "checked=\"checked\"" : ""; 
      return "<input type='checkbox' onclick=\"ajaxSaveParent('" + opts.rowId + "', this);\" " + bchk + " value='" + cval + "' offval='no' />"; 
  }

And lastly the function containing the ajax call: 最后,包含ajax调用的函数:

 function ajaxSaveParent(rowid, curCheckbox) {
        var val = curCheckbox.checked ? "Y" : "N";

        $.ajax({
          type: 'POST',
          url: "DataService.asmx/Update",
          data: { id: rowid, yesno: val },
          success: function (data, textStatus) {
              if (textStatus == "success") {
                  //success code here
              }
          },
          error: function (data, textStatus) { //error code here }
      });
 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM