Ändra storlek på GridWeb i webbläsarfönstret
Möjliga användningsscenarier
Ibland vill du att Aspose.Cells.GridWeb ska ändra storlek på sig själv i enlighet med webbläsarfönstret. Du kanske behöver GridWeb bör alltid justera sin storlek (höjd, bredd) och kompatibel med webbläsarfönstrets storlek. Aspose.Cells.GridWeb tillhandahåller klientsidanändra storlek() funktion för ändamålet. Dessutom kan du till och med ändra storlek på GridWeb-kontrollen i webbläsarfönstret. Du kan till exempel använda det nedre högra handtaget (via mus) för att anpassa dess bredd/höjd i fönstret. Du måste också inkludera/specificera jquery Javascript-filer för att få det att fungera i sidkällan i ditt projekt.
Använder GridWebs storleksändringsmetod
Följande kod kommer att kontrollera om storleksändring sker var 100:e millisekund. När det inte finns någon åtgärd för att ändra storlek, tror den att storleksändringen är klar nu. Vi använder en exempelmallfil som importeras till GridWeb. Vi använder kod på klientsidan för att ändra storlek på GridWeb. Skärmdumpen visar att GridWeb ändrar storleken på sig själv när den ändrar storlek på webbläsarfönstret.
Exempelkod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//---------------------------------------------------------------------- | |
//------ResizeGridWebUsingResizeMethod.aspx----------------------------- | |
//---------------------------------------------------------------------- | |
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ResizeGridWebUsingResizeMethod.aspx.cs" Inherits="Aspose.Cells.GridWeb.Examples.CSharp.WorkingWithGridWebClientSideScript.ResizeGridWebUsingResizeMethod" %> | |
<%@ Register TagPrefix="acw" Namespace="Aspose.Cells.GridWeb" Assembly="Aspose.Cells.GridWeb" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<style type="text/css"> | |
.fullheight { | |
display: inline-block; | |
min-height: 80%; | |
height: 90%; | |
padding: 0; | |
position: relative; | |
margin-right: -0.3em; | |
vertical-align: top; | |
} | |
html, body, form { | |
background: #b6b7bc; | |
font-size: .80em; | |
font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif; | |
margin: 0px; | |
padding: 0px; | |
color: #000000; | |
min-height: 99%; | |
height: 100%; | |
overflow: visible; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function doResizing() { | |
//alert("I'm done resizing for the moment"); | |
$("#GridWeb1")[0].resize(); | |
}; | |
var resizeTimer; | |
$(window).resize(function () { | |
clearTimeout(resizeTimer); | |
resizeTimer = setTimeout(doResizing, 100); | |
}); | |
</script> | |
<title>Using GridWeb’s resize method</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div style="width: 100%; height: 100%; overflow: visible;"> | |
<span id="gridwebpanel" class="fullheight"> | |
<acw:GridWeb ID="GridWeb1" runat="server" Width="100%" Height="100%" ShowLoading="true" XhtmlMode="true" | |
PresetStyle="Standard" EnableAJAX="true"> | |
</acw:GridWeb> | |
</span> | |
</div> | |
</form> | |
</body> | |
</html> | |
//---------------------------------------------------------------------- | |
//------ResizeGridWebUsingResizeMethod.aspx.cs-------------------------- | |
//---------------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Aspose.Cells.GridWeb.Examples.CSharp.WorkingWithGridWebClientSideScript | |
{ | |
public partial class ResizeGridWebUsingResizeMethod : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (Page.IsPostBack == false && this.GridWeb1.IsPostBack == false) | |
{ | |
string filePath = Server.MapPath("~/01_SourceDirectory/sampleResizableGridWeb.xlsx"); | |
GridWeb1.ImportExcelFile(filePath); | |
} | |
} | |
} | |
} |
Göra GridWeb storleksändringsbar med hjälp av jquery ui-funktionen
Följande kod gör att GridWeb-kontrollen kan ändras i storlek i webbläsarfönstret. Du kan till exempel använda det nedre högra handtaget för att anpassa storleken på GridWeb i fönstret. Vi använder samma mallfil som först importeras till GridWeb. Vi använder jquery-skript för att göra GridWeb storleksanpassbar. Skärmdumpen visar att storleken på GridWeb har ändrats med sitt nedre högra handtag i webbläsarfönstret.
Exempelkod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//---------------------------------------------------------------------- | |
//------MakingGridWebResizableUsingResizablejQueryUiFeature.aspx-------- | |
//---------------------------------------------------------------------- | |
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MakingGridWebResizableUsingResizablejQueryUiFeature.aspx.cs" Inherits="Aspose.Cells.GridWeb.Examples.CSharp.WorkingWithGridWebClientSideScript.MakingGridWebResizableUsingResizablejQueryUiFeature" %> | |
<%@ Register TagPrefix="acw" Namespace="Aspose.Cells.GridWeb" Assembly="Aspose.Cells.GridWeb" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js" type="text/javascript"></script> | |
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" /> | |
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> | |
<script type="text/javascript"> | |
$(function () { | |
$("#resizable").resizable( | |
{ | |
resize: function () { | |
$("#GridWeb1").height($("#resizable").height()); | |
$("#GridWeb1").width($("#resizable").width()); | |
$("#GridWeb1")[0].resize(); | |
} | |
} | |
); | |
}); | |
</script> | |
<title>Making GridWeb resizable using resizable jquery ui feature</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div id="resizable" class="ui-widget-content"> | |
<acw:GridWeb ID="GridWeb1" runat="server" XhtmlMode="True" Height="400px" Width="100%"> | |
</acw:GridWeb> | |
</div> | |
</form> | |
</body> | |
</html> | |
//---------------------------------------------------------------------- | |
//------MakingGridWebResizableUsingResizablejQueryUiFeature.aspx.cs----- | |
//---------------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Aspose.Cells.GridWeb.Examples.CSharp.WorkingWithGridWebClientSideScript | |
{ | |
public partial class MakingGridWebResizableUsingResizablejQueryUiFeature : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (Page.IsPostBack == false && this.GridWeb1.IsPostBack == false) | |
{ | |
string filePath = Server.MapPath("~/01_SourceDirectory/sampleResizableGridWeb.xlsx"); | |
GridWeb1.ImportExcelFile(filePath); | |
} | |
} | |
} | |
} |