2

我需要从单元格表中获取值。如果您知道该怎么做,我将不胜感激。

尝试了几天,但我不知道如何获取 columnID 和 ROWID

我找到了这个,但它不起作用

.igGrid( "getCellValue", rowId:object, colKey:string );

这是代码(我如何从表中获取值)?

$.ig.loader(function () {
$("#grid2").igGrid({

autoGenerateColumns: false,
renderCheckboxes: true, 

columns:[                
            { headerText: "X", key: "x", dataType: "number", width: "40%"},
            { headerText: "Y", key: "y", dataType: "number", width: "40%"},
            { headerText: "Z", key: "z", dataType: "number", width: "40%"},

        ],

//dataSource: data,

height: "400px",
width: "100%",
features:[
            {
                name: "Filtering",
                allowFiltering: true,
                type: "local"
            },
            {
                name: "Selection",
                mode: "row"
            },
            {
                name: "Updating",
                enableAddRow: false,
                editMode: "row",
                // event raised after end row editing but before dataSource was updated
                editCellEnding: function (evt, ui) {
                    // get cell’s checkbox value when it is changed
                    if (ui.update) {
                        if (ui.columnKey === "nid") {
                            logEvent("editCellEnded event fired. Column Key = " +
                        ui.columnKey + "; Row Index = " +
                        ui.rowID + "; Cell Value = " +
                        ui.value + "; Update = " +
                        ui.update);
                        }
                    }
                },
                enableDeleteRow: false,
                columnSettings: [
                {
                    columnKey: "x",

                }, 
                {
                    columnKey: "y"
                }, 
                {
                    columnKey: "z"
                }]
            }

        ]
});

$.ajax({
    type: "POST",
    url: "http://cmsdemo.trueoffice.com/feature-json",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data){
        $("#grid2").igGrid({
        dataSource: data 
     });
    }
});
    $("#grid2").live("iggridupdatingdatadirty", function (event, ui) {
            $("#grid2").igGrid("commit");
            return false;
        });
    // show the raised event
        function logEvent(message) {
            var evntWrap = $("#eventList");
            $(evntWrap).append("<div>" + message + "<div>");
            $(evntWrap).prop("scrollTop", $(evntWrap).prop("scrollHeight"));
        }
 });

//Functions         
function Filter() {
      var columnSettings = $("#grid1").igGridFiltering("option", "columnSettings");

        var expr = $("#filterExpr").val(),
            condition = $("#cond_list").val(),
            filterColumn = $("#filterColumn").val();
        $("#grid1").igGridFiltering("filter", ([{fieldName: filterColumn, expr: expr, cond: condition}]));
    }

    function SetConditions() {
        var filterColumn = $("#filterColumn").val();
        $("#cond_list option:selected").removeAttr("selected");
        if (filterColumn === "title" || filterColumn === "nid") {
         $("#cond_list .stringCondition").attr("disabled", "disabled");
         $("#cond_list .numberCondition").removeAttr("disabled").eq(0).attr("selected", "selected");
        }
        else {
            $("#cond_list .stringCondition").removeAttr("disabled").eq(0).attr("selected", "selected");
            $("#cond_list .numberCondition").attr("disabled", "disabled");
        }
    }
    function buttonClickHandler(buttonId) {
    alert("Button with id " + buttonId + " was clicked");
}   

4

1 回答 1

2

有时对 IG 感到非常沮丧。但是,您有几个选择。如果您只关心您可以看到的列...即,您隐藏了一些列但您不需要访问它们,那么您可以在editRowEndoreditRowEnding事件触发时访问 ui 对象。否则,您需要使用底层dataSourcedataView. 这是它的外观,包括网格:

 grid = $("#grid").igGrid({
   height: 400,
   width: null,     //if null, the grid should stretch to fit
   virtualization: false,
   autoGenerateColumns: false,
   columns: [
     ......
   ],
   autoupdate: false,
   features: [
    { name: "Updating",
        enableAddRow: true,
        enableDeleteRow: true,
        editMode: 'row',
        editMode: 'cell',
        enableDataDirtyException: false,
        rowAdded: function(evt, ui) {
          alert("this is a visible column (title): " + ui.values.title);
        },
        editRowEnded: function(evt, ui) {
          var row = ui.owner.grid.dataSource.dataView()[ui.owner._rowIndex];
          alert("this is my id column, which is hidden: " + row.id);                  
        },
        rowDeleted: function(e, ui) {
          ... do something
        }
    },
于 2013-07-24T17:06:44.927 回答