Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

你可以在控件中给数据排序,并且制定一个排序规则,比如指定行或者指定列来排序等。

你也可以指定多个排序关键字(先按照某一行或者一列排序,再按照某一行或者一列排序,依此类推)。

使用 sortRange 方法来对数据进行排序。使用 sortRange 中的 sortInfo 对象来设置排序的关键字,升序还是降序等。



示例代码

点击按钮来按照第一列排序

JavaScript

Copy Code

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
var activeSheet = spread.getActiveSheet();
activeSheet.setValue(0, 0, 10);
activeSheet.setValue(1, 0, 100);
activeSheet.setValue(2, 0, 50);
activeSheet.setValue(3, 0, 40);
activeSheet.setValue(4, 0, 80);
activeSheet.setValue(5, 0, 1);
activeSheet.setValue(6, 0, 65);
activeSheet.setValue(7, 0, 20);
activeSheet.setValue(8, 0, 30);
activeSheet.setValue(9, 0, 35);

$("#button1").click(function(){
     //按照 Column1 升序排列
    activeSheet.sortRange(-1, 0, -1, 1, true, [{index:0, ascending:true}]);
   });

 $("#button2").click(function(){
    //Sort Column1 by descending at every button click.
     activeSheet.sortRange(-1, 0, -1, 1, true, [
       {index:0, ascending:false}
     ]);
 });
//在界面上添加两个按钮
<input type="button" id="button1" value="button1"/>
<input type="button" id="button2" value="button2"/>

示例代码

点击按钮来按照 sortInfo 设置的排序标准来排序。

JavaScript

Copy Code

activeSheet.setRowCount(6);
activeSheet.setValue(0, 0, 10);
activeSheet.setValue(1, 0, 100);
activeSheet.setValue(2, 0, 100);
activeSheet.setValue(3, 0, 10);
activeSheet.setValue(4, 0, 5);
activeSheet.setValue(5, 0, 10);
activeSheet.setValue(0, 1, 10);
activeSheet.setValue(1, 1, 40);
activeSheet.setValue(2, 1, 10);
activeSheet.setValue(3, 1, 20);
activeSheet.setValue(4, 1, 10);
activeSheet.setValue(5, 1, 40);

    $("#button1").click(function(){
        //创建 SortInfo 对象,主要关键字是 column1,次要关键字是 column2。
        var sortInfo = [
            {index:0, ascending:true},
            {index:1, ascending:true}];
        ///执行该排序
        activeSheet.sortRange(0, -1, 6, -1, true, sortInfo);
    });

//在页面中添加按钮
<input type="button" id="button1" value="button1"/>


 

  • No labels