Kendo Grid - Copy datasource from one grid to another - kendo-ui

i have a requirement to copy values from one grid datasource to another grid data source, but grid both schema are different.
As we can find out from the bellow example as in, Grid One - only 3 columns are present and Grid Two - 4 columns. Here I need to copy data from Grid Two (COL4, COL2,COL3) and bind to Grid One without page refresh.
Grid One
COL4 COL2 COL3
XX YY ZZ
zz xy SS
Grid Two
COL1 COL2 COL3 COL4
XX YY ZZ SA
zz AD SS DA
For reference, i have used bellow code, here it copying all the elements from GridTwo to GridOne, but i need specific columns like (COL4, COL2,COL3).
gridTwo.select().each(function () {
var dataItem = gridTwo.dataItem($(this));
gridOne.dataSource.add(dataItem);
});
gridOne.refresh();
Thanks.

You can create a new DataSource.
var data = [];
gridTwo.select().each(function () {
var dataItem = gridTwo.dataItem($(this));
data.push({ COL4: dataItem.COL4, COL2: dataItem.COL2, COL3: dataItem.COL3 });
});
var ds = new kendo.data.DataSource({
data: data
});
gridOne.setDataSource(ds);
gridOne.dataSource.read();

Related

Oracle Apex Interactive Grid Master Multiple selection to Detail

I have a master detail Interactive Grid, all is working fine. As soon as I select a row on the master it populates the details interactive grid without a problem.
The thing I'm trying to achieve is that I want to select two or more rows on the master and populate all the data on the details grid.
Is it possible?
I found your question very challenging and it can be useful to other users.
I'm not sure if the proposed solution works under every condition since it is not tested enough. I resolve your problem with APEX_COLLECTIONS, some JS and PL/SQL.
But lets start in the example below I will use the standard HR data set, more precisely the DEPARTMENTS and EMPLOYEEStables.
In the Before Header section add one process defined as:
BEGIN
APEX_COLLECTION.CREATE_OR_TRUNCATE_COLLECTION(
p_collection_name => 'SELECTED_MASTER');
END;
Also create one Ajax Callback process, name it SELECTOR:
BEGIN
APEX_COLLECTION.TRUNCATE_COLLECTION(p_collection_name => 'SELECTED_MASTER');
FOR i IN 1..apex_application.g_f01.count LOOP
APEX_COLLECTION.ADD_MEMBER ( p_collection_name => 'SELECTED_MASTER',
p_n001 => apex_application.g_f01(i));
END LOOP;
htp.p('Done.');
END;
Create the first IG: Load Dept
under Source section set the following values:
Location : Local Database
Type : Table/View
Table Owner : Parsing Schema
Table Name : Department
Columns:
APEX$ROW_SELECTOR (!important)
APEX$ROW_ACTION
DEPTNO
DNAME
LOC
Static ID : loadDept
on the IG create a DA:
Name : SELECT_ROWS
Event : Selection Change [Interactive Grid]
Selection Type : Region
Region : Load Dept
now add one True action which executes the following JS:
var array = []
var i;
for (i = 0; i < this.data.selectedRecords.length; i++) {
array[i] = this.data.selectedRecords[i][0];
}
apex.server.process( "SELECTOR", {
f01: array,
},
{
dataType : 'text',
success: function( data ) {
apex.region( "loadEmp" ).refresh();
},
error: function( jqXHR, textStatus, errorThrown ) {
apex.message.clearErrors();
apex.message.showErrors([
{
type: "error",
location: "page",
message: errorThrown,
unsafe: false
}
]);
}
} );
The second IG: Load Emp
Static ID : loadEmp
under Source section set the following values:
Location : Local Database
Type : SQL Query
SQL Query
SELECT EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO,
CREATED,
LAST_UPDATED
FROM EMPLOYEES
WHERE
APEX_COLLECTION.COLLECTION_MEMBER_COUNT ('SELECTED_MASTER') = 0
OR
(
APEX_COLLECTION.COLLECTION_MEMBER_COUNT ('SELECTED_MASTER') > 0
AND
EXISTS (SELECT 'x' FROM apex_collections
WHERE collection_name = 'SELECTED_MASTER' AND n001 = DEPTNO)
)
Although it works the first record in the master table is always selected, and that is the only known bug or feature. :)

Create a DAX Table with recursive row calculations

I want to create a table like
VAR startYear = 2000
VAR startAmount = 100
LeasingFee_Datatable =
DATATABLE (
"Year", INTEGER,
"Amount", DOUBLE,
{
// LOOP Until i reach 25 rows or some other condition i like to add later.
{startYear , startAmount },
{ROW0+1, (ROW1+2)100%}
}
)
I can't find a way to define a variable for to use inside DAX Table. Any suggestions ?

ASP.net LINQ on DataView to use Like query

I want to filter a DataView but DV.Rowfilter is taking too much time .
dv.RowFilter = "ProductName like '%" + searchtxt + "%'";
So I decided to use the LINQ but how to implement above like query in LINQ ?
LINQ is not more efficient in general, but it can increase readability and maintainability.
So you can try Linq-To-DataSet:
var query = from row in dv.Table.AsEnumerable()
let productName = row.Field<string>("ProductName")
where productName.Contains(searchtxt)
select row;
DataTable tbl = query.CopyToDataTable(); // use this as DataSource or use tbl.DefaultView
Here the same with method syntax:
var query = dv.Table.AsEnumerable()
.Where(row => row.Field<string>("ProductName").Contains(searchtxt));
MSDN: Creating a DataView Object with LINQ to DataSet
i have tried your second solution, but now its throwing the exception
"The source contains no DataRows." and actually the DataTable which i
make as DataTable.AsEnumerable() , it has the rows in it
The table contains rows but the filter skips all of them.
You could use if(query.Any()){...} to check if there are rows:
DataTable tbl = dv.Table.Clone(); // creates an empty table with the same columns
if(query.Any())
tbl = query.CopyToDataTable();

How take join two datatable in LINQ and extract its value using loop

I have taken value in two datatable
Dt1
EMPID empname sickleave casual leave earned leave
1 john 1
Dt2
EmpId empname sickleave casualleave earned leave
1 john 5 5 5
in dt2 defaul value of leave are give (total leave for a employee)and in dt1 leave taken by employee are given.
so I want to show result in grid in this form like
Empname sickleave casualleave earnedleave
john 0/5 0/5 1/5
for this i wrote code like this
var result = from p in dt1.AsEnumerable()
join q in dt2.AsEnumerable() on p.Field<int>("EmpID") equals q.Field<int>("EmpID") into UP
from q in UP.DefaultIfEmpty()
select new
{
EmpID = p.Field<int>("EmpID"),
EmpName = p.Field<string>("EmpName"),
SickLeave = (p.Field<int?>("Sick Leave") ?? 0).ToString() + "/" + (q.Field<int?>("Sick Leave") ?? 0).ToString(),
CasualLeave = (p.Field<int?>("Casual Leave") ?? 0).ToString() + "/" + (q.Field<int?>("Casual Leave") ?? 0).ToString(),
EarnedLeave = (p.Field<int?>("Earned Leave") ?? 0).ToString() + "/" + (q.Field<int?>("Earned Leave") ?? 0).ToString()
};
GridViewLeaveSummary.DataSource = result;
GridViewLeaveSummary.DataBind();
this code is working fine but i want to make leave dynamic means grid show no of leave according to leave type table (means all leaves field come from datable) because i have to add different leave type .in this code olny three leaves are given and i have to add more leaves .means in grid no of leaves show acording to the database
Thanks

Linq databinding issue....data doesnt show up in gridview ...I get the message that number and name field are not found in the data source

List<Emp> employees = new List<Emp>();
Emp e1 = new Emp();
e1.number = 2;
e1.name = "Dinesh";
employees.Add(e1);
Emp e2 = new Emp();
e2.number = 3;
e2.name = "Vishal";
employees.Add(e2);
var query = from n in employees
orderby n.name descending
select n;
GridView1.DataSource = query;
GridView1.DataBind();
You should try to debug the situation as possibly some settings in GridView are not exactly matching DataSource.
Easily you could bind your grid in design time to type Emp, which would generate all the columns for you:
In YourGridFile.Designer.cs add:
this.GridView1.AutoGenerateColumns = true;
this.GridView1.DataSource = typeof(Emp);
somewhere before ResumeLayout lines.
Then you will be able to compare what you have set up manually and what should be in columns definitions.

Resources