Dataset

Verifying column information of DataSet

This describes how to verify the DataSet column's information and how to change column type.

Dataset_column_information_0

DataSet can get name, size and type information by using the getColumnInfo.

Verifying DataSet Information

this.Button00_onclick = function (obj:Button, e:ClickEventInfo)
{
 var strText = new String();
 for (var i = 0; i < this.Dataset00.getColCount(); i++) 
 {
  var objColInfo = this.Dataset00.getColumnInfo(i);
  strText += "ID = " + objColInfo.name;
  strText += " SIZE = " + objColInfo.size;
  strText += " type = " + objColInfo.type;
  strText += "\n";
 }
 this.TextArea00.set_value(strText);
}

DataSet column information changing

this.Button01_onclick = function (obj:Button, e:ClickEventInfo)
{
 var objColInfo = this.Dataset00.getColumnInfo(2);
 objColInfo.set_type("INT");
}

Changing column information by using script is not recommended. We recommend you to configure DataSet by using XPLATFORMs’ service.

Verifying Changed Column Information

this.Button02_onclick = function (obj:Button, e:ClickEventInfo)
{
 var strText = new String();
 for (var i = 0; i < this.Dataset00.getColCount(); i++) 
 {
  var objColInfo = this.Dataset00.getColumnInfo(i);
  strText += "ID = " + objColInfo.name;
  strText += " SIZE = " + objColInfo.size;
  strText += " type = " + objColInfo.type;
  strText += "\n";
 }
 this.TextArea00.set_value(this.TextArea00.value + strText);
}

Can we change DataSet column type by using Script?

Source Location

Sample\DataSet\np_Dataset_ColumnInfo.xfdl

Summary

It explanation is about how to implements sum of DataSet columns.

Dataset_getSum_0

Implementation Expr

Dataset_getSum_1

Dataset_getSum_3

Int type and Float type can implement  getSum directly without conversion.

Dataset_getSum_2

Dataset_getSum_4

Reference

Location of SummaryBand can be expressed on top on grid by changing Properties of grid.

default : SummaryBand is expressed on bottom, RightBand is expressed on right.

top : SummaryBand is expressed on top, RightBand is expressed on right.

Source Location

Sample\DataSet\np_Dataset_getSum.xfdl

Filter

Using filter implementing like search criteria

After input employee name we can implement %Like%, like% and = different search criteria.

Dataset_filter_0

Related Method

filter

This method is used to show the records from Dataset records by satisfied conditions.

% Like% implementation

It will implement the % front and back side of input value of employ and search all the values matching to these criteria.
this.Button00_onclick = function (obj:Button, e:ClickEventInfo)
{
 this.ds_data.filter("String(employ).substr(0," + this.ed_name.value.length + ").indexOf('" +  this.ed_name.value + "') >= 0");
}

Like% implementation

It implements the search criteria by adding % value at the end of empoy.
this.Button02_onclick = function (obj:Button, e:ClickEventInfo)
{
 this.ds_Employ.filter("String(employ).indexOf('" + this.ed_name.value + "') >= 0");
}

= implementation

If you wish to search the exact matching values to employ, this returns the exact matching values the search criteria.
this.btn_search_onclick = function (obj:Button, e:ClickEventInfo)
{
 this.ds_data.filter("employ=='" + this.ed_name.value + "'");
}

I want to know how to implement search by using Like.

Source Location

Sample\DataSet\np_Dataset_Filter.xfdl

Removing duplicate data using by Filter

This describes the way to remove the duplicate row in searched data.

Dataset_Distinct_filter_0

Main Source Content

Basic Filter content

this.Button02_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 var sExpr = "rowidx==dataset.findRowExpr(\"code=='\" + code + \"'\")"; 
 this.Dataset00.filter(sExpr);    
}

rowidx means the row index of Dataset.

Setting Filter on several column using function made by user

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 this.gf_distincDsFilter(this.Dataset00, "code,name"); 
}
this.gf_distincDsFilter = function(objDs, sColID)
{
 var arrArgs = this.gf_Trim(sColID).split(",");
 var sFilterExpr  = "";
 var sFindRowExpr = "";
 for (var i=0; i<arrArgs.length; i++)
 {
  if (objDs.getColumnInfo(arrArgs[i]) == null) continue;
  
  sFindRowExpr += (this.gf_IsNull(sFindRowExpr) == false) ? " && " : "";
  sFindRowExpr += "" + arrArgs[i] + "=='\" + " + arrArgs[i] + " + \"'";
 }
 
 if (this.gf_IsNull(sFindRowExpr) == false) {
  sFilterExpr = "rowidx==dataset.findRowExpr(\"" + sFindRowExpr + "\")";
 }
 objDs.filter(sFilterExpr);
}

Source Location

Sample\DataSet\np_Dataset_Distinct_Filter.xfdl

Searching multiple column using findRow Expr

You can search multiple column using findRowExpr method provided Dataset.

findRowExpr

Main Source Content

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 var nRow = this.ds_data.findRowExpr("department.toString().indexOf('" + this.ed_department.value.replace("'","\\'") + "')>=0&&employee.toString().indexOf('" + this.ed_employee.value.replace("'","\\'") + "')>=0");
 
   
 if(nRow >= 0)
 {
  this.ds_data.set_rowposition(nRow);  
 } else {
  this.alert("There is no matched conditions.");
  return;
 } 
}

this.ed_department.value.replace("'","\\'") this condition part is needed to handle the value including single quote(') in real data.

Source Location

Sample\DataSet\np_Dataset_findRowExp.xfdl

Event controlling by using enableevent property

Dataset_Enableevent_0

When we are working with large amount of data on screen using DataSet, we may have experience Flicker problem.
To prevent this Flicker problem we can control it by using enableevent property, this property handles flicker problem.

Related Method

enableevent

By following the enableevent property of DataSet, we can run/stop the events occurring from the DataSet.

onnrowposchanged

This event is occurred when we change rowposition property of DataSet.

Main source content

this.btn_execute0_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
  this.ds_data.set_enableevent(false);
  this.ds_data.addRow();
  this.ds_data.set_enableevent(true); 
}

After setting enableevent false, it is necessary to set it true.

If you don't set true after false, the event may not work properly.

Source Location

Sample\DataSet\np_Dataset_EnableEvent.xfdl

Verifying the original buffer content of DataSet

Dataset_RowType_0

Related Method

getRowType

The following Dataset methods are using to obtain the state of the specified record.
1: The original record state
2: Added record state
4: Modified record state
8: Deleted record state

getOrgColumn

This method is used to get specified column's value before changing the record.

getDeletedColumn

This method is used to get deleted number of record from Dataset.

getDeletedColumn

This method is used to get column's value of deleted record.

Main source content

/*
 * File Name   : Comp_Dataset_RowType
 * Discription : Verifying the recorded Original buffer content and RowType of Dataset
 */
this.btn_execute0_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 this.ds_data.deleteRow(this.ds_data.rowposition);
}
this.btn_execute1_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 this.ds_org.addColumn("COL_TYPE", "STRING");
 
 for (var i = 0; i < this.ds_data.colcount; i++) 
 {
  this.ds_org.addColumn(this.ds_data.getColID(i), "STRING");
 }
 
 this.fn_orgDataset();
}
/*
 * Function Name : fn_orgDataset
 * Description   : Verifying recorded OriginBuffer
 * Parameter     : 
 * Return        : 
 * Example       : fn_orgDataset();
 */
this.fn_orgDataset = function()
{
 var sOrgCol = "";
 var sOrgVal = "";
 this.ds_org.clearData(); 
 
 // Modifying content
 for (var i = 0; i < this.ds_data.rowcount; i++) 
 {
  var nRowType = this.ds_data.getRowType(i);
  if (nRowType == 4)
  {
   this.ds_org.addRow();
   this.ds_org.setColumn(this.ds_org.rowposition, "COL_TYPE", nRowType);
   for (var j = 0; j < this.ds_data.colcount; j++) 
   {
    sOrgCol = this.ds_data.getColID(j);
    sOrgVal = this.ds_data.getOrgColumn(i, sOrgCol);
    this.ds_org.setColumn(this.ds_org.rowposition, sOrgCol, sOrgVal);
   }
  }
 }
 
 // Modifying content
 for (var i = 0; i < this.ds_data.getDeletedRowCount(); i++) 
 {
  this.ds_org.addRow();
  this.ds_org.setColumn(this.ds_org.rowposition, "COL_TYPE", 8);
  for (var j = 0; j < this.ds_data.colcount; j++) 
  {
   sOrgCol = this.ds_data.getColID(j);
   sOrgVal = this.ds_data.getDeletedColumn(i, sOrgCol);
   this.ds_org.setColumn(this.ds_org.rowposition, sOrgCol, sOrgVal);
  }
 }
 
 this.grd_output.createFormat();
}

Can we verify rowType and originalBuffer information?

Source Location

Sample\DataSet\np_Dataset_RowType.xfdl

By using Script Creating GlobalDataSet, LocalDataSet

Dataset_UseScript_0

Using new operator we can create DataSet Dynamically on the global zone and form.

The main source content

/*
 * File Name   : Comp_Dataset_UseScript
 * Description : By using Script Creating GlobalDataSet, LocalDataSet
 */
/*  Button Click  */
this.btn_execute_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
    var objGdS = new Dataset; 
    application.addVariable("gds_data", objGdS, "global");
    application.gds_data.set_name("gds_data");
    application.gds_data.addColumn("COL0","String");
    application.gds_data.addColumn("COL1","String");
    application.gds_data.addRow();
    application.gds_data.setColumn(application.gds_data.rowposition,"COL0","global COL0");
    application.gds_data.setColumn(application.gds_data.rowposition,"COL1","global COL1");
    this.grd_output0.set_binddataset("gds_data");
    this.grd_output0.createFormat();
      
    var objLdS = new Dataset;
    objLdS.set_name("ds_data");
    this.addChild("ds_data", objLdS);  
    this.ds_data.addColumn("COL0","String");
    this.ds_data.addColumn("COL1","String");
    this.ds_data.addRow();
    this.ds_data.setColumn(this.ds_data.rowposition,"COL0","1");
    this.ds_data.setColumn(this.ds_data.rowposition,"COL1","first");
    this.ds_data.addRow();
    this.ds_data.setColumn(this.ds_data.rowposition,"COL0","2");
    this.ds_data.setColumn(this.ds_data.rowposition,"COL1","second");
    this.grd_output1.set_binddataset("ds_data"); 
    this.grd_output1.createFormat();
    this.Edit00.set_value('global dataset count : ' + application.all["gds_data"].rowcount);
    this.Edit01.set_value('local  dataset count : ' + this.all["ds_data"].rowcount);
}

Reference Details

GlobalDataSet

Global DataSet can be used at any position in application, but it can be accessed in the memory until the application termination so depending on the application we must decide the location to use

Can we create Global DataSet dynamically?

Want to know DataSet creation by using Script?

Source Location

Sample\DataSet\np_Dataset_UseScript.xfdl

Reverting the Changed column information to original value

After modifying the retrieved data, we can  revert to original data

Dataset_ChangeRowtype_0

Main source content

/*
 * File Name   : Dataset_ChangeRowtype1
 * Description : Selected record in the DataSet return to the original value
 */
 
 /* set rowtype */
this.btn_execute_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 var iRowCount = this.ds_data.getRowCount();
 var iColCount = this.ds_data.getColCount();
 
 for (var i = 0; i < iRowCount; i++)
 {
        if (this.ds_data.getColumn(i, "COL0") == 1 && this.ds_data.getRowType(i) != "1")
        {
            for (var j = 0; j < iColCount; j++)
            {   
                if (this.ds_data.getColumn(i, j) != this.ds_data.getOrgColumn(i, j))
                {
                    this.ds_data.setColumn(i, j, this.ds_data.getOrgColumn(i, j));
                }
            }
            
            this.ds_data.setColumn(i, "COL0", 1);            
            this.ds_data.set_updatecontrol(false);
            this.ds_data.setRowType(i,Dataset.ROWTYPE_NORMAL);
            this.ds_data.set_updatecontrol(true);
        }
 }
}

setRowType, updatecontrol, getRowType

Source Location

Sample\DataSet\np_Dataset_ChangeRowtype1.xfdl

Converting changed rowtype to normal

If rowType changes in DataSet due to selecting checkbox on the grid, rowType can be changed to normal

Dataset_ChangeRowtype_1

If we don't want to send modified rowtype, we can changed it to normal so we can prevent sending data to server side.

The main source of information

this.btn_execute_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
 중략...
  if (bChkFlag == true && nChkCnt == 1)
   {
    this.ds_data.setRowType(i, Dataset.ROWTYPE_NORMAL);
   }            
  }
 }
 this.ds_data.set_updatecontrol(true);
 this.ds_data.set_enableevent(true);
}

Is it possible to change the rowType by script which is modified in DataSet,?

setRowType, updatecontrol

Source Location

Sample\DataSet\np_Dataset_ChangeRowtype2.xfdl

Determine whether the DataSet is updated

Using getRowType method of DataSet we can determine the modifications.

Dataset_CheckUpdated_0

Related Method

updatecontrol

This attribute is used to set whether the rowType should be changed automatically or not.
If we changed updatecontrol attribute to false, we can change rowType by using setRowType method.

getDeletedRowCount

This method is used to obtain the number of rows that have been deleted from Dataset.

getRowType

We can get rowType of Dataset. For rowType reference nexacro studio Help(Appendix>Constant>Dataset>Row Type)

The main source of information

this.fn_isUpdate = function(objDs)
{
 var bRtn = false;
 if (objDs.updatecontrol) 
 {
  if (objDs.getDeletedRowCount() > 0) 
  {
            bRtn = true
            return bRtn;
        }
 }
 var nRowType;
 for (var i = 0; i < objDs.getRowCount(); i++) 
 {
  nRowType = objDs.getRowType(i);
  if (nRowType == 2 || nRowType == 4 || nRowType == 8) 
  {
   bRtn = true;
   break;
  }
 }
 return bRtn;
}

Update, rowType, Updatecontrol

Source Location

Sample\DataSet\np_Dataset_CheckUpdated.xfdl