AdvancedDataGrid Flex - Row not getting added under correct column - apache-flex

I'm dynamically adding rows and they don't seem to go under the proper column. I have all of my headers in 'headerArray' and the data i need to add is in the string 'item'.
//create an item to work with
var chartItem:Object = new Object();
for( var j:int = 0; j < columnResult.length ; j++ )
{
var item:String = removeformat(removetd(columnResult[j]));
//grab the header (this is which column the value will be added
var head:String = headerArray[j];
//set the value to header (pair)
chartItem[head] = item;
}
//add the chartItem (row) to the main collection
arr.addItem(chartItem);
tableCollection = arr;
It's getting all the headers properly and setting the chartItem (from inspection with debugger). When it gets to a row (building from html) where there is an item that only has values for some of the columns, it doesn't add the information under the right column, it just goes from left to right and adds it in the next one.
The behaviour is kind of strange because the chartItem clearly has the right header value and corresponding item value in it, but like I said they don't end up under the right column.
tableCollection gets set as the dataprovider for the grid later (not modified since)

var chartItem:Object = new Object();
var span:int = 0;
for( var j:int = 0; j < columnResult.length ; j++ )
{
var colSpan:int = this.getColSpan(columnResult[j]);
var item:String = removeformat(removetd(columnResult[j]));
//grab the header (this is which column the value will be added
var head:String;
if (colSpan >1){
head = headerArray[j];
span = colSpan;
} else {
if (span == 0){
head = headerArray[j];
} else {
head = headerArray[j+span-1]
}
}
//set the value to header (pair)
chartItem[head] = item;
}
//add the chartItem (row) to the main collection
arr.addItem(chartItem);
If i read the span attribute for the row, i set the NEXT row to be at column+previous colspan. then all the rows line up properly.

Related

How to script editor to clear cells but keep formula in certain cells

Is there a way to keep formulas in certain cells when I have a clear cell script. At the moment it clears everything and removes my formula.
Cells with formulas are - 'H2' & 'K2'
function reset() {
var sheet = SpreadsheetApp.getActive();
sheet.getRange("F3:K8").clearContent();
}
Clearing your content will always clear the formula in a cell. A cell has a text/number literal or a formula in it. There's not a function that will clear one and not the other.
But, you can check to see if a cell contains a formula, and if so, don't clear the content for it. That will functionally do what you want.
function reset() {
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange('F3:K8');
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
for (var i = 1; i <= numRows; i++) {
for (var j = 1; j <= numCols; j++) {
if (range.getCell(i,j).getFormula());
{
range.getCell(i,j).clearContent();
}
}
}
}

XRTable in devexpress report with more then 282 rows empties the report

If you add more than 282 XRTableRow dynamically into a XRTable, the XRTable and any subsequent contents will not show in the report.
Please note that it is always required to call the XRTable.BeginInit and XRTable.EndInit methods if you modify XRTable.Rows and XRTableRow.Cells collections at runtime.
As for the height of a table, explicitly specify it only if cells' content is not expected to stretch the cells (e.g. this may happen when their CanGrow property is enabled).
public XRTable CreateXRTable() {
int cellsInRow = 3;
int rowsCount = 3;
float rowHeight = 25f;
XRTable table = new XRTable();
table.Borders = DevExpress.XtraPrinting.BorderSide.All;
table.BeginInit();
for (int i = 0; i < rowsCount; i++) {
XRTableRow row = new XRTableRow();
row.HeightF = rowHeight;
for (int j = 0; j < cellsInRow; j++) {
XRTableCell cell = new XRTableCell();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
table.EndInit();
return table;
}
then add this table to report specific band i,m adding this to Detail band
this.Detail.Controls.Add(CreateXRTable());

Multiple pages in the same PDF reporting with PDFsharp

I am getting values from database and collection of all values are larger than a single page. Number of pages are unknown and it might differ report by report. Currently, only 1 page of multiple pages is being printed but same information in every pages. I want continuous information in the pages not same information in every page. How can I do that with PDFsharp?
Here I am giving my codes to understand...
Document doc = new Document();
//Create table
var sec = doc.AddSection();
var table = sec.AddTable();
table.Format.Font.Size = 6;
table.Borders.Distance = 0;
table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
var renderer = new DocumentRenderer(doc);
renderer.PrepareDocument();
int totalPage = renderer.FormattedDocument.PageCount;
for (int i = 1; i <= totalPage; ++i)
{
PdfPage pdfPage = pdf.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
renderer.RenderObject(gfx, XUnit.FromMillimeter(10), XUnit.FromMillimeter(10), XUnit.FromMillimeter(double.MaxValue), table);
gfx.Dispose();
}
You can have MigraDoc create the whole document without a for loop:
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
Your for loop has a variable i that is not used in your code. If you want to do it the complicated way, use RenderPage instead of RenderObject.
See also:
http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx
I'm not sure if this may be of help to anyone but if you want to break your table into multiple pages you can use this method:
public Document MultiplePagesPerDocument(Document document, DocumentForm documentForm, Section section, DocumentPage page, DataTable dt, int maxTableRows)
{
_document = document;
if (dt.Rows.Count > maxTableRows)
{
for (int i = 1; i <= dt.Rows.Count; i++)
{
// Break the table onto next page for maxTableRows
if (i % maxTableRows == 0)
{
section = _document.LastSection;
section.AddPageBreak();
Paragraph paragraph = section.AddParagraph();
paragraph.Format.SpaceAfter = "3cm";
_position = new PageItemPosition()
{
Height = "3.0cm",
Width = "8.0cm",
Top = "3.0cm",
LeftPosition = ShapePosition.Left,
TopPosition = ShapePosition.Top
};
object tableSection = page.AddPageTextFrame(section, _position, string.Empty);
documentForm.GenerateSection(section, tableSection, 170, "Table", dt);
}
}
}
return this._document;
}

Client side sorting on ASP.NET MVC WebGrid

I have a partial view which contain an MVC WebGrid as below
<div id="grid">
#{
var grid = new WebGrid(source: Model.Items,
defaultSort: "Name",
rowsPerPage: 100);
}
#grid.GetHtml(columns: grid.Columns(
grid.Column(columnName: "Name", header: "Name", canSort:true),
grid.Column(columnName: "Code", header: "Code")
))
</div>
This partial view is loaded using Jquery ajax call and result is inserted into a DIV in the main page.
The table render fine but my problem is that the sorting always generates a callback to the server. I want the sorting to happen at the client side only. Is it possible using WebGrid without using external datatables like jQuery datatable?
Thanks in advance
You should probably implement Cline-Side Sorting by yourself according to the loaded table take a look here...
NOTE!: you could always make it more generic by using html attributes to tag your WebGrid.
Tag the table with 'data-clineSideSort=true' then add a jquery event that will attach the JS functionality to all such tables holding this property...
function SortTable(sortOn)
{
var table = document.getElementById('results');
var tbody = table.getElementsByTagName('tbody')[0];
var rows = tbody.getElementsByTagName('tr');
var rowArray = new Array();
for (var i = 0, length = rows.length; i < length; i++)
{
rowArray[i] = new Object;
rowArray[i].oldIndex = i;
rowArray[i].value = rows[i].getElementsByTagName('td')[sortOn].firstChild.nodeValue;
}
if (sortOn == sortedOn) {
rowArray.reverse();
}
else {
sortedOn = sortOn;
/*
Decide which function to use from the three:RowCompareNumbers,
RowCompareDollars or RowCompare (default).
For first column, I needed numeric comparison.
*/
if (sortedOn == 0) {
rowArray.sort(RowCompareNumbers);
}
else {
rowArray.sort(RowCompare);
}
}
var newTbody = document.createElement('tbody');
for (var i = 0, length = rowArray.length; i < length; i++)
{
newTbody.appendChild(rows[rowArray[i].oldIndex].cloneNode(true));
}
table.replaceChild(newTbody, tbody);
}
function RowCompare(a, b)
{
var aVal = a.value;
var bVal = b.value;
return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
}
// Compare number
function RowCompareNumbers(a, b)
{
var aVal = parseInt(a.value);
var bVal = parseInt(b.value);
return (aVal - bVal);
}
// compare currency
function RowCompareDollars(a, b)
{
var aVal = parseFloat(a.value.substr(1));
var bVal = parseFloat(b.value.substr(1));
return (aVal - bVal);
}
Have a look at jQuery Tablesorter. It can be applied to any well formed table (ie, has thead and tbodyelements. The only gotcha I can think of here is to make sure you bind table sorter once the data has been loaded in your ajax call.

save state of a dataGrid: visible columns, columns width and order

I want to save remotely (on a database) the state (visible columns, columns width and order) of a Flex3 DataGrid.
For width and visibility I can simply save them by accessing each column attribute.. ugly but possible..
But for the order? Do I have to create the dataGrid dynamically??
Any idea is appreciated
thanks
In my case I have saved the order by header name (I'm making an assumption that your DataGrid always has the same columns and header names).
for (var n:Number = 0; n< datagrid.columns.length; n++)
{
var thiscol:DataGridColumn = DataGridColumn(datagrid.columns[n]);
colArray.addItem(thiscol.headerText);
}
Then I can restore the column order by retrieving the ordered list of column headers, and swapping the position of columns in the datagrid as required.
for (var n:Number = 0; n < colArray.length; n++)
{
moveColumnTo(String(colArray.getItemAt(n)), n);
}
I have defined a function moveColumnTo() to perform the switch.
private function moveColumnTo(columnName:String, columnIndex:Number):void
{
// Find current column position
var i:Number = -1;
for (var n:Number = 0; n < datagrid.columns.length; n++)
{
if (DataGridColumn(datagrid.columns[n]).headerText == columnName)
{
i = n;
break;
}
}
if (i == -1 || i == columnIndex) return; // Don't shift column
this.mx_internal::shiftColumns(i, columnIndex); // Shift column to required position
}
Why can't you just save the order as you're looping through each column?
for(var i:int = 0; i < dataGrid.columns.size; i++)
{
var column:DataGridColumn = dataGrid.columns[i];
arr.push({column.visible, column.width, i});
}

Resources