Extjs更新表格中的数据

    通过Extjs的ajax框架从后台获取数据,然后填入表格的特定单元格

    historyStore为含有属性Location的数据存储容器

    Ext.getCmp("historyGrid")为获取id为historyGrid的Ext.grid.GridPanel数据表格

function getAjaxLocation(Lgt, Lat, Index) {
    Ext.Ajax.request({
        method: "POST",
        timeout: 5 * 60 * 1000,
        url: "AjaxBack/GPSMonitor.ashx",
        params: {
            t: 'sendLocation',
            Lgt: Lgt,
            Lat: Lat
        },
        success: function (response) {
            //将返回的数据赋给索引为Index的数据
            historyStore.getAt(Index).data.Location = response.responseText;
            //实时更新特定位置的文本内容
            Ext.getCmp("historyGrid").getView().getCell(Index, 6).childNodes[0].innerHTML = response.responseText;
        },
        failure: function (response) {
            Ext.MessageBox.alert(GPSlang.ts);
        }
    });
}
    var historyGrid = new Ext.grid.GridPanel({
        id: "historyGrid",
        region: "south",
        layout: 'fit',
        height: 130,
        store: historyStore,
        cm: historycm,
        stripRows: true,
        autoScroll: true,
        loadMask: false,
        autoDestroy: true,
        border: false,
        listeners: {//双击监听事件
            'rowdblclick': function (grid, rowIndex, e) {
                var record = grid.getStore().getAt(rowIndex);

                var zoom = document.getElementById('routemap').contentWindow.getZoom();
                if (zoom < 15) {
                    document.getElementById('routemap').contentWindow.setZoom(15);
                } else {
                    document.getElementById('routemap').contentWindow.setZoom(zoom);
                }
                var verdata = _Wars2WgsByAlgorithm.Wgs84Encrypt(parseFloat(record.data.Latitude), parseFloat(record.data.Longitude), 'baidu');
                if (Ext.isFunction(document.getElementById('routemap').contentWindow.setCenter))
                    document.getElementById('routemap').contentWindow.setCenter(verdata.Lng, verdata.Lat);
                if (Ext.isFunction(document.getElementById('routemap').contentWindow.addMarker)) {
                    var tmpdata = record.data;
                    tmpdata.SimId = hisvid;
                    tmpdata.Lng = verdata.Lng;
                    tmpdata.Lat = verdata.Lat;
                    document.getElementById('routemap').contentWindow.addMarker(hisvid, record.data.Licenseplate, verdata.Lng, verdata.Lat, record.data.Speed, record.data.Direction, record.data.Status);
                }
            }
        }
    });
var historyStore = new Ext.data.ArrayStore({
    fields: ["Licenseplate", "Latitude", "Longitude", "Location", "Speed", "Direction", "Gpstime", "Status", "Jrlc", "Thermometer1", "Thermometer2"]
});
function updatesinglegps1(single) {
    var verdata = _Wars2WgsByAlgorithm.Wgs84Encrypt(parseFloat(single.c), parseFloat(single.b), 'baidu');
    var plate = displayName;
    if (plate.length > 0) {
        getAjaxLocation(single.b, single.c, hisindex);
        if (Ext.isFunction(document.getElementById('routemap').contentWindow.addMarker)) {//添加地图
            var data = {};
            data.SimId = hisvid;
            data.Licenseplate = plate;
            data.Latitude = single.c;
            data.Longitude = single.b;
            data.Lng = verdata.Lng;
            data.Lat = verdata.Lat;
            //data.Location = single.g;
            data.Speed = single.d;
            data.Direction = getDirectionDesc(single.e);
            data.Angle = single.e;
            data.Gpstime = single.a;
            data.Status = getMonitorTerminalStatus(parseInt(single.f));
            data.Jrlc = single.h;
            data.Thermometer1 = single.t1;
            data.Thermometer2 = single.t2;

            document.getElementById('routemap').contentWindow.addMarker(data);
        }
        var data = {};
        data.Licenseplate = plate;
        data.Latitude = single.c;
        data.Longitude = single.b;
        data.Location = "";
        //data.Location = single.g;
        data.Speed = single.d;
        data.Direction = getDirectionDesc(single.e);
        data.Angle = single.e;
        data.Gpstime = single.a;
        data.Status = getMonitorTerminalStatus(parseInt(single.f));
        data.Jrlc = single.h;
        data.Thermometer1 = GetThermometer(single.t1);
        data.Thermometer2 = GetThermometer(single.t2);


        document.getElementById('routemap').contentWindow.drawLine(hisvid, verdata.Lng, verdata.Lat);//地图上历史轨迹划线

        if (Ext.isFunction(document.getElementById('routemap').contentWindow.setCenter))
            document.getElementById('routemap').contentWindow.setCenter(verdata.Lng, verdata.Lat);
        //地图放大缩小
        var zoom = document.getElementById('routemap').contentWindow.getZoom();

        if (zoom < 14) {

            document.getElementById('routemap').contentWindow.setZoom(14);
        } else {

            document.getElementById('routemap').contentWindow.setZoom(zoom);
        }
        //显示数据
        var record = new Ext.data.Record(data);
        historyStore.add(record);
        Ext.getCmp("historyGrid").getView().focusRow(hisindex);
    }
}
原文地址:https://www.cnblogs.com/yyxiangjava/p/5634042.html