|
スクロールの同期
クライアント側スクリプトで提供されるonScrollイベントを使用すると
クライアント側の処理において、2つのSPREAD間でスクロールの同期をとることができます。
onScroll イベントはシートをスクロールした時に発生します。
このサンプルでは上下いずれかのSPREADを水平方向、または垂直方向にスクロールすると
もう一方のSPREADも同様にスクロールされます。
| 製品ID | 製品分類 | 製品名 | 4月計画 | 5月計画 | 6月計画 | 7月計画 | 8月計画 | 9月計画 | 10月計画 | 11月計画 | 12月計画 | 1月計画 | 2月計画 | 3月計画 |
1 | 10001 | 乳製品 | 酪農ミルク | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 | 4,500 | 6,000 |
2 | 20001 | 清涼飲料水 | いよかんドリンク | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 | 2,700 | 2,700 |
3 | 20002 | 清涼飲料水 | ぶどうジュース | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 | 4,800 | 4,800 |
4 | 20003 | 清涼飲料水 | マンゴードリンク | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 | 500 | 1,050 |
5 | 30001 | ビール | 激辛ビール | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 | 8,500 | 10,000 |
6 | 30002 | ビール | モルトビール | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 | 2,780 | 4,000 |
7 | 20004 | 清涼飲料水 | ぶどうの街 | 500 | 300 | 200 | 700 | 500 | 300 | 200 | 700 | 500 | 300 | 200 | 700 |
8 | 30003 | ビール | オリエントの村 | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 | 9,580 | 9,000 |
9 | 40002 | 焼酎 | 吟醸 ほめごろし | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 | 9,000 | 9,500 |
10 | 40003 | 焼酎 | 大吟醸 オリエント | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 | 6,000 | 5,000 |
|
| 製品ID | 製品分類 | 製品名 | 4月実績 | 5月実績 | 6月実績 | 7月実績 | 8月実績 | 9月実績 | 10月実績 | 11月実績 | 12月実績 | 1月実績 | 2月実績 | 3月実績 |
1 | 10001 | 乳製品 | 酪農ミルク | 5,600 | 5,100 | 4,600 | 6,100 | 5,600 | 5,100 | 4,600 | 6,100 | 5,600 | 5,100 | 4,600 | 6,100 |
2 | 20001 | 清涼飲料水 | いよかんドリンク | 1,100 | 3,100 | 2,800 | 2,800 | 1,100 | 3,100 | 2,800 | 2,800 | 1,100 | 3,100 | 2,800 | 2,800 |
3 | 20002 | 清涼飲料水 | ぶどうジュース | 3,100 | 3,600 | 4,900 | 4,900 | 3,100 | 3,600 | 4,900 | 4,900 | 3,100 | 3,600 | 4,900 | 4,900 |
4 | 20003 | 清涼飲料水 | マンゴードリンク | 2,100 | 1,100 | 600 | 1,150 | 2,100 | 1,100 | 600 | 1,150 | 2,100 | 1,100 | 600 | 1,150 |
5 | 30001 | ビール | 激辛ビール | 5,600 | 8,100 | 8,600 | 10,100 | 5,600 | 8,100 | 8,600 | 10,100 | 5,600 | 8,100 | 8,600 | 10,100 |
6 | 30002 | ビール | モルトビール | 3,100 | 3,600 | 2,880 | 4,100 | 3,100 | 3,600 | 2,880 | 4,100 | 3,100 | 3,600 | 2,880 | 4,100 |
7 | 20004 | 清涼飲料水 | ぶどうの街 | 600 | 400 | 300 | 800 | 600 | 400 | 300 | 800 | 600 | 400 | 300 | 800 |
8 | 30003 | ビール | オリエントの村 | 8,100 | 9,600 | 9,680 | 9,100 | 8,100 | 9,600 | 9,680 | 9,100 | 8,100 | 9,600 | 9,680 | 9,100 |
9 | 40002 | 焼酎 | 吟醸 ほめごろし | 6,100 | 7,100 | 9,100 | 9,600 | 6,100 | 7,100 | 9,100 | 9,600 | 6,100 | 7,100 | 9,100 | 9,600 |
10 | 40003 | 焼酎 | 大吟醸 オリエント | 1,100 | 5,100 | 6,100 | 5,100 | 1,100 | 5,100 | 6,100 | 5,100 | 1,100 | 5,100 | 6,100 | 5,100 |
11 | 40005 | 焼酎 | 麦焼酎 ちこちこ | 1,100 | 1,600 | 1,300 | 1,358 | 1,100 | 1,600 | 1,300 | 1,358 | 1,100 | 1,600 | 1,300 | 1,358 |
12 | 10002 | 乳製品 | 酪農ミルク(低脂肪) | 601 | 302 | 480 | 556 | 601 | 302 | 480 | 556 | 601 | 302 | 480 | 556 |
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class clientsynchroscroll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// クライアントイベントの設定
string js = "var spid1='" + FpSpread1.ClientID + "';";
js += "var spid2='" + FpSpread2.ClientID + "';";
js += "setTimeout(\"inite()\", 1000);" + "\r\n";
js += "function inite()" + "\r\n";
js += "{" + "\r\n";
js += " var s1=document.getElementById(spid1);" + "\r\n";
js += " var s2=document.getElementById(spid2);" + "\r\n";
js += " if (document.all) {" + "\r\n";
js += " if (s1.addEventListener) {" + "\r\n";
js += " s1.addEventListener(\"Scroll\", scrolled, false);" + "\r\n";
js += " s2.addEventListener(\"Scroll\", scrolled, false);" + "\r\n";
js += " } else {" + "\r\n";
js += " s1.onScroll = scrolled;" + "\r\n";
js += " s2.onScroll = scrolled;" + "\r\n";
js += " }" + "\r\n";
js += " } else {" + "\r\n";
js += " s1.addEventListener(\"Scroll\", scrolled, false);" + "\r\n";
js += " s2.addEventListener(\"Scroll\", scrolled, false);" + "\r\n";
js += " }" + "\r\n";
js += "}" + "\r\n";
ClientScript.RegisterStartupScript(this.GetType(), "onStartUpScript", js, true);
if (IsPostBack) return;
// セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = false;
FpSpread2.ActiveSheetView.DataAutoCellTypes = false;
// データ連結
DataSet ds1 = new DataSet();
ds1.ReadXml(MapPath("../App_Data/datapln.xml"));
FpSpread1.DataSource = ds1;
DataSet ds2 = new DataSet();
ds2.ReadXml(MapPath("../App_Data/datares.xml"));
FpSpread2.DataSource = ds2;
FarPoint.Web.Spread.SheetView sheet1 = FpSpread1.Sheets[0];
FarPoint.Web.Spread.SheetView sheet2 = FpSpread2.Sheets[0];
// SPREAD初期化
InitSpread(sheet1,FpSpread1);
InitSpread(sheet2,FpSpread2);
}
private void InitSpread(FarPoint.Web.Spread.SheetView sheet,FarPoint.Web.Spread.FpSpread spread)
{
// SPREAD設定
spread.CommandBar.Visible = false;
spread.Style.Add("position", "relative");
spread.Width = 650;
spread.Height = 150;
spread.UseClipboard = false;
// フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%");
// シート設定
sheet.PageSize = sheet.RowCount;
// 列幅の設定
sheet.Columns[0].Width = 50;
sheet.Columns[1].Width = 70;
sheet.Columns[2].Width = 130;
for (int i = 3; i < spread.ActiveSheetView.ColumnCount; i++)
{
sheet.Columns[i].Width = 65;
}
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 各列のセル型を設定
FarPoint.Web.Spread.GeneralCellType gnr = new FarPoint.Web.Spread.GeneralCellType();
gnr.FormatString = "#,##0";
sheet.Columns[3, sheet.ColumnCount - 1].CellType = gnr;
sheet.Columns[3, sheet.ColumnCount - 1].HorizontalAlign = HorizontalAlign.Right;
}
}
|
Partial Public Class clientsynchroscroll
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' クライアントイベントの設定
Dim js As String = "var spid1='" + FpSpread1.ClientID & "';"
js += "var spid2='" + FpSpread2.ClientID & "';"
js += "setTimeout(""inite()"", 1000);" & System.Environment.NewLine
js += "function inite()" & System.Environment.NewLine
js += "{" & System.Environment.NewLine
js += " var s1=document.getElementById(spid1);" & System.Environment.NewLine
js += " var s2=document.getElementById(spid2);" & System.Environment.NewLine
js += " if (document.all) {" & System.Environment.NewLine
js += " if (s1.addEventListener) {" & vbCr & vbLf
js += " s1.addEventListener(""Scroll"", scrolled, false);" & System.Environment.NewLine
js += " s2.addEventListener(""Scroll"", scrolled, false);" & System.Environment.NewLine
js += " } else {" & System.Environment.NewLine
js += " s1.onScroll = scrolled;" & System.Environment.NewLine
js += " s2.onScroll = scrolled;" & System.Environment.NewLine
js += " }" & System.Environment.NewLine
js += " } else {" & System.Environment.NewLine
js += " s1.addEventListener(""Scroll"", scrolled, false);" & System.Environment.NewLine
js += " s2.addEventListener(""Scroll"", scrolled, false);" & System.Environment.NewLine
js += " }" & System.Environment.NewLine
js += "}" & System.Environment.NewLine
ClientScript.RegisterStartupScript(Me.[GetType](), "onStartUpScript", js, True)
If IsPostBack Then
Return
End If
' セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = False
FpSpread2.ActiveSheetView.DataAutoCellTypes = False
' データ連結
Dim ds1 As New System.Data.DataSet()
ds1.ReadXml(MapPath("../App_Data/datapln.xml"))
FpSpread1.DataSource = ds1
Dim ds2 As New System.Data.DataSet()
ds2.ReadXml(MapPath("../App_Data/datares.xml"))
FpSpread2.DataSource = ds2
Dim sheet1 As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)
Dim sheet2 As FarPoint.Web.Spread.SheetView = FpSpread2.Sheets(0)
' SPREAD初期化
InitSpread(sheet1, FpSpread1)
InitSpread(sheet2, FpSpread2)
End Sub
Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView, ByVal spread As FarPoint.Web.Spread.FpSpread)
' SPREAD設定
spread.CommandBar.Visible = False
spread.Style.Add("position", "relative")
spread.Width = 650
spread.Height = 150
spread.UseClipboard = False
' フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%")
' シート設定
sheet.PageSize = sheet.RowCount
' 列幅の設定
sheet.Columns(0).Width = 50
sheet.Columns(1).Width = 70
sheet.Columns(2).Width = 130
For i As Integer = 3 To spread.ActiveSheetView.ColumnCount - 1
sheet.Columns(i).Width = 65
Next
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 各列のセル型を設定
Dim gnr As New FarPoint.Web.Spread.GeneralCellType()
gnr.FormatString = "#,##0"
sheet.Columns(3, sheet.ColumnCount - 1).CellType = gnr
sheet.Columns(3, sheet.ColumnCount - 1).HorizontalAlign = HorizontalAlign.Right
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="clientsynchroscroll" CodeFile="clientsynchroscroll.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server">
<script type="text/javascript">
function scrolled(e) {
var e = e || window.event;
var s = e.target || e.srcElement;
var str;
if (!(s.id.lastIndexOf("FpSpread1") < 0))
str = s.id.replace("FpSpread1", "FpSpread2");
else
str = s.id.replace("FpSpread2", "FpSpread1");
var v = document.getElementById(s.id + "_view");
var v2 = document.getElementById(str + "_view");
v2.scrollLeft = v.scrollLeft;
v2.scrollTop = v.scrollTop;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<farpoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" >
<Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif"></Background>
</CommandBar>
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
<ClientEvents Scroll="scrolled" />
<TitleInfo BackColor="#E7EFF7" ForeColor="" HorizontalAlign="Center" VerticalAlign="NotSet" Font-Size="X-Large"></TitleInfo>
</farpoint:FpSpread>
<br />
<farpoint:FpSpread ID="FpSpread2" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" >
<Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif"></Background>
</CommandBar>
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
<ClientEvents Scroll="scrolled" />
<TitleInfo BackColor="#E7EFF7" ForeColor="" HorizontalAlign="Center" VerticalAlign="NotSet" Font-Size="X-Large"></TitleInfo>
</farpoint:FpSpread>
</asp:Content>
|
|