找回密码
 立即注册

QQ登录

只需一步,快速开始

Dtttax

银牌会员

265

主题

663

帖子

2116

积分

银牌会员

积分
2116
Dtttax
银牌会员   /  发表于:2024-11-6 13:58  /   查看:159  /  回复:5
1金币
本帖最后由 Wilson.Zhang 于 2024-11-8 09:11 编辑


1、用table 绑定了数据后自动生成了一个filter。同时样式也会变化,设置sheet默认的全局样式无效。
  有没有直接设置整个全局的样式,比如字体,背景色 border,而不用一个个单元格设置。
let table = sheet.tables.add("Table1", 0, 0, 1, headers.length);
table.bindColumns(tableColInfos);//绑定table.
sheet.setDefaultStyle(defaultStyle); 没有效果

2.如果添加一列怎么filter也跟着变化,下面代码不生效。如果用sheet.rowFilter就可以。


const range = new GC.Spread.Sheets.Range(startRow,  startCol, rowCount, colCount);
  const rowFilter = new GC.Spread.Sheets.Filter.HideRowFilter(range);
  sheet.tables.findByName('Table1').rowFilter(rowFilter);//不生效
  sheet.rowFilter(rowFilter) //有效

3 怎么获取了filter的contidtion后。然后修改contidtion属性设置进去。是不是获取
filterItemMap 然后设置filterItemMap




5 个回复

倒序浏览
Wilson.Zhang
超级版主   /  发表于:2024-11-6 17:35:45
沙发
本帖最后由 Wilson.Zhang 于 2024-11-6 17:37 编辑

您好!关于您关心的问题,解答如下:

问题1:通过Worksheet:setDefaultStyle()可以对整张sheet设置统一的样式,如下动图所示。
setDefaultStyle.gif

也可以通过CellRange:setStyle()对指定区域设置统一的样式。

问题2:Table:rowFilter()用以获取Table的筛选器对象,不能通过该接口设置Table的筛选器,如下图所示。
1730885827856.png994622192.png

问题3:可以通过HideRowFilter:addFilterItem()为指定列增加筛选项,将需要筛选的条件封装为Condition对象。
如果需要清除列上原有的筛选条件,可以通过HideRowFilter:removeFilterItems()实现。

回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2024-11-6 18:15:35
板凳
本帖最后由 Dtttax 于 2024-11-6 19:46 编辑

    1、
let table=sheet.tables.findByName('Table1');
     let rowFilter=table.rowFilter();
    let condition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.textCondition);
     table.rowFilter().addFilterItem(lastCol,condition)
这样试过不行应该是table没有加入一列,
table.insertColumns(3, 1);这样也能加一列如果要table加一列怎么加。



2、sheet.rowFilter  toJSON 是空
sheet.rowFilter(rowFilter);

var rowFilter = sheet.rowFilter(); //这个能取到值
sheet.rowFilter().toJSON()//这个是空

3 想直接table 的rowFilter.fromJSON 或者sheet.rowFilter().fromJSON(filterJson)这样是否支持。

let filterJson=filter.toJSON();
        let filterItemMap=JSON.parse(filterStr);
        filterJson.filterItemMap=filterItemMap;
        table.rowFilter().fromJSON(filterJson);


4.设置了 sheet.setDefaultStyle(defaultStyle)下面还是在这样是不是要设置table的样式。

image.png708782653.png



回复 使用道具 举报
Wilson.Zhang
超级版主   /  发表于:2024-11-7 11:08:33
地板
Dtttax 发表于 2024-11-6 18:15
1、
let table=sheet.tables.findByName('Table1');
     let rowFilter=table.rowFilter();

1. 如果需要对Table新增行列,是需要通过Table:insertRows()和Table:insertColumns()分别添加行和列,新增的列自动附带有筛选器。HideRowFilter:addFilterItems()只能对Table中存在的列有效。

2. 经测试,未能复现问题,如下图所示。不确定是否是版本之间的差异,我在最新的17.1.8版本测试,需要确认下您使用的是哪个版本?
rowFilter-toJSON.png650593566.png

3. 在HideRowFilter中公开了fromJSON()和toJSON(),即可支持筛选器对象的序列化。

4. 结合您前后提供的信息,需要确认下您是否想要添加的Table的样式与Worksheet一样呢?由于插入Table时会产生默认的Table样式,如果不需要,可以清除Table的样式,参考如下代码:
  1. sheet.tables.remove('TableName', GC.Spread.Sheets.Tables.TableRmoveOptions.keepData);
复制代码

可以参考官网API文档了解详情:
TableManager:remove()--https://demo.grapecity.com.cn/spreadjs/help/api/classes/GC.Spread.Sheets.Tables.TableManager#remove
TableRemoveOptions--https://demo.grapecity.com.cn/spreadjs/help/api/enums/GC.Spread.Sheets.Tables.TableRemoveOptions

回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2024-11-7 21:51:53
5#
设置 table的filter 。然后sheet的rowFilter没有设置。用这个代码table.rowFilter().fromJSON(filterJson);  
fromJSON下面的代码怎么不生效,也就是不会有过滤。

设置一个这样的filterjson字符串的代码
  let filterJson=JSON.parse(filterStr);
  // filterJson.filterItemMap=filterItemMap;
   table.rowFilter().fromJSON(filterJson);




{"range":{"row":1,"rowCount":849,"col":0,"colCount":31},"typeName":"HideRowFilter","dialogVisibleInfo":{},"filterItemMap":[{"index":1,"conditions":[{"conType":2,"compareType":0,"expected":"044002100113","useWildCards":false}]}],"filteredColumns":[1],"filterButtonVisibleInfo":{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"17":true,"18":true,"19":true,"20":true,"21":true,"22":true,"23":true,"24":true,"25":true,"26":true,"27":true,"28":true,"29":true},"showFilterButton":true,"filteredOutRows":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849]}
回复 使用道具 举报
Wilson.Zhang
超级版主   /  发表于:2024-11-8 09:10:43
6#
本帖最后由 Wilson.Zhang 于 2024-11-8 09:14 编辑
Dtttax 发表于 2024-11-7 21:51
设置 table的filter 。然后sheet的rowFilter没有设置。用这个代码table.rowFilter().fromJSON(filterJson); ...

一般情况下,通过HideRowFilter:fromJSON()成功反序列化筛选器对象后即已生效,由于此时未对Table执行筛选,因此无法看到筛选条件的生效结果,需要对筛选器执行filter()方法才能令序列化数据中的筛选条件生效。如下动图所示:
TableRowFilter.gif


可以参考如下博客了解详情:
https://gcdn.grapecity.com.cn/showtopic-74149.html
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部