ExtJS Grid - Display Multiples rows in one row - extjs

I am having below json data in ExtJS store. I am using Ext.grid.Panel to show this content with colum Name and Phone.
{
"name": "Doris Ryan",
"phone": "1-536-934-9500"
},
{
"name": "Nissim Hines",
"phone": "1-937-975-0044"
},
{
"name": "Walter Gallegos",
"phone": "863-4112"
},
{
"name": "Miranda Boyd",
"phone": "1-820-817-5049"
},
{
"name": "Sonya Booth",
"phone": "468-0669"
},
{
"name": "Rose Steele",
"phone": "1-581-774-8023"
},
So with this I am getting Grid in below format
Name Phone
Doris Ryan 1-536-934-9500
Nissim Hines 1-937-975-0044
Walter Gallegos 863-4112
Miranda Boyd 1-820-817-5049
But what i want to display the content in Grid as described below
Name Phone Name Phone
Doris Ryan 1-536-934-9500 Nissim Hines 1-937-975-0044
Walter Gallegos 863-4112 Miranda Boyd 1-820-817-5049
User is able to edit the phone number. So also share details on how will I handle the updates on grid.

The solution to this is to change how you assemble the data in the model, and then you also change the exposure via the grid.
ExtJS does not have the property to automatically replicate two rows of records in a single row.
Crete a model like this:
Ext.define('YourApp.model.yourFeature.Model', {
extend: 'Ext.data.Model',
fields: [{
name: 'Phone1',
type: 'string'
}, {
name: 'Name1',
type: 'string'
}, {
name: 'Phone2',
type: 'string'
}, {
name: 'Name2',
type: 'string'
}]
});
Define your data, like your question:
var data = [{
"name": "Doris Ryan",
"phone": "1-536-934-9500"
}, {
"name": "Nissim Hines",
"phone": "1-937-975-0044"
}, {
"name": "Walter Gallegos",
"phone": "863-4112"
}, {
"name": "Miranda Boyd",
"phone": "1-820-817-5049"
}, {
"name": "Sonya Booth",
"phone": "468-0669"
}, {
"name": "Rose Steele",
"phone": "1-581-774-8023"
}]
So you make a kind of odd / even logic to abound your record.

Related

How can I group rows in react-data-table-component?

I am facing a problem when I need to group rows in a table using react-data-table-component.
My dataset:
const cars = [{
"brand": "audi",
"model": "a4",
"hp": "200",
},
{
"brand": "audi",
"model": "a5",
"hp": "300",
},
{
"brand": "audi",
"model": "rs6",
"hp": "500",
},
{
"brand": "tesla",
"model": "model 3",
"hp": "200",
},
{
"brand": "tesla",
"model": "model x",
"hp": "450",
}
];
The table should be structured like this:
How can I achieve this?
I am using hook-like style.
One can use cell property to render. So I create some index to track which brand has already been rendered and if a brand is already on the table it just returns an empty cell.
The code I am using:
const [brandIndex, setBrandIndex] = useState<(string | undefined)[]>([]);
const renderBrand = useCallback((row: CarDto) => {
const alreadyRendered = brandIndex.some(b => b === row.brand);
if (alreadyRendered) {
return null;
} else {
setBrandIndex(brandIndex.concat(row.brand));
return <span>{row.brand}</span>;
}
},[setBrandIndex, brandIndex])
//...
{
id: "brand",
name: "Brand",
selector: (row) => row.brand || "",
cell: renderBrand,
sortable: true,
resizable: true,
width: "200px",
},
Unfortunately this code is not working, all brands in my table are empty after rendering. The table renders a lot of times, so I assume that index contains all brands. The last rendering returns null in the first column.

How to move MongoDB document fields to an array of objects?

Given a collection of documents similar to the following document
{
"_id": {
"$oid": "60582f08bf1d636f4b762ebc"
}
"experience": [{
"title": "Senior Customer Success Account Manager",
"company": "Microsoft",
"tenure": 8
}, {
"title": "Senior Service Delivery Manager",
"company": "Microsoft",
"tenure": 34
}],
"company3": "Oracle",
"tenure3": 10,
"title3": "Senior Customer Success Manager - EMEA |Oracle Marketing Cloud"
}
How would I write an updateMany or other shell command to move company3, tenure3 and title3 inside the experience array as a new object {company: <company3 value>, title: <title3 value>, tenure: <tenure3 value>} ?
Seems like you're looking for this aggregation update:
db.collection.update({},
[
{
$set: {
experience: {
$concatArrays: [
"$experience",
[
{
company: "$company3",
title: "$title3",
tenure: "$tenure3"
}
]
]
}
}
},
{
$unset: "company3"
},
{
$unset: "tenure3"
},
{
$unset: "title3"
}
],
{
multi: true
})
Playground: https://mongoplayground.net/p/xoEveE0rdBN

Add optgroups to angular-selectize asynchronously

I am using angular-selectize directive in my project. For this, I need to load optgroups asynchronously. So far I have tried multiple approaches but none of them works. The problem is, you cannot use the data returned by a promise synchronously. On the flip side, I have also been unable to initialize selectize from inside a promise callback. Given below is the code I currently have. Note that it is only to be used to get the idea of the data I'm playing with, not to present it as something you can consider right.
app.js
$http
.get('/get-categories')
.then(getCategoriesSCB, getCategoriesFCB);
function getCategoriesSCB(response) {
if(typeof(response.data) === 'object') {
posControl.menuCategories = response.data[0];
posControl.menuCategoryGroups = response.data[1];
}
else {
getCategoriesFCB(response);
}
}
function getCategoriesFCB(response) {
console.log(response);
}
posControl.menuConfig = {
valueField: 'id',
labelField: 'title',
placeholder: 'Select Category',
optgroupField: 'class',
optgroupLabelField: 'label',
optgroupValueField: 'value',
optgroups: posControl.menuCategoryGroups,
maxItems: 1,
searchField: ['title', 'category'],
onInitialize: function(selectize) {
console.log('selectize is here');
},
}
index.html
<selectize config="POSCtrl.menuConfig" options="POSCtrl.menuCategories" ng-model="POSCtrl.menuModel"></selectize>
data returned by ajax call
[
// this array has to be used for options.
[{
"class": "57b83830babb9",
"category": "Food Menu",
"id": "57b83855b23f9",
"title": "Beverages"
}, {
"class": "57b83830babb9",
"category": "Food Menu",
"id": "57b83855c05de",
"title": "Cuisines"
}, {
"class": "57b83830babb9",
"category": "Food Menu",
"id": "57b83855cdcb4",
"title": "Steaks"
}, {
"class": "57b83830d0899",
"category": "Wholesale Coffee",
"id": "57b83830d0899",
"title": "Wholesale Coffee"
}],
// this array has to be used for optgroups
[{
"value": "57b83830babb9",
"label": "Food Menu"
}, {
"value": "57b83830d0899",
"label": "Wholesale Coffee"
}]
]
You should be able to load a selectize asynchronously by setting the values directly on the posControl.menuConfig:
function getCategoriesSCB(response) {
if (typeof(response.data) === 'object') {
posControl.menuConfig.options = response.data[0];
posControl.menuConfig.optgroups = response.data[1];
}
}

how to parse and bind complex JSON in backbone.js with view model controller approach

I am using one complex JSON structure as a result of one Ajax call. Here I need "many different kinds of nested models in one parent model".For each person, I am using one EmployeeContext. I need this as my parent model.
Within this EmployeeContext, I need many different collection having associated model. Example:I have a collection named expenseContextCollection with "expense" as the model of the same.And I have travellContextCollection with travel as the model.
I need to display details of each model and need to update the same and save back to mongo database.
Currently I am using one file for model (EmployeeModel.js),one file for view (EmployeeView.js), one file for template (EmployeePage.html).
And in the EmployeeView.js file I am setting the result of ajax call to model.
initialize: function(instance) {
this.model.set({
"travelContext": ajaxResponse.EmployeeContext.travellContextCollection
});
this.model.set({
"expenseContext": ajaxResponse.EmployeeContext.expenseContextCollection
});
this.render();
}
But I need this travelContext as a backbone collection so that I can loop though it and take each travel model from it
How Can I handle this situation with model view collection approach in backbone.js ?
following is one sample of JSON structure:
{
"EmployeeContext": {
"expenseContextCollection": [{
"currencyType": "INR",
"empID": "00123456",
"imageID": "d69ce74a9b4e075d2111cf0619e27c503d",
"toDate": "11-12-2015",
"billDate": "11-12-2015"
}, {
"currencyType": "INR",
"empID": "00123456",
"imageID": "ab2f78d9f9e7897b4a11c5bc82618d09f4",
"toDate": "25-01-2016",
"billDate": "20-01-2016",
}],
"claimContextCollection": [],
"travellContextCollection": [{
"empID": "00123456",
"isOneWay": true,
"eligibility": "true",
"createTravelRequest": {
"purposeOfTravelDetailsCollection": [{
"isPrimary": "true",
"purposeOfTravel": "Trans",
"leadOpportunity": "BAA12346",
"account": "BASS"
}],
"travelDetailsCollection": [{
"travelToCity": "BANGALORE",
"travelType": "DTR",
"travelTime": "",
"travelFromCity": "CHENNAI",
"checkoutDate": "25-01-2016",
"travelDate": "20-01-2016",
"travelTo": "INDIA",
"travelFrom": "INDIA"
}],
"Preference": {
"empnum": "00123456",
"employeeProfilePreference": {
"emergencyContacCity": "9412345678",
"travelSeatPreference": "aisle",
"smsNotification": "true",
"emergencyContactNumber": "9412345678",
"frequentFlierPreference": {
"frequentFlierNo": "EJK7861",
"frequentFlierAirlines": "Virgin"
},
"employeeContactNumber": "8712345678",
"emergencyContactPerson": "Moll Mathew",
"emergencyContactAddress": "KOOODC",
"travelMealPreference": "vegetarian"
}
},
"otherDetails": {
"smsNotification": true,
"forexAmount": "0",
"forexRequiredDate": "20141002",
"employeeContactNumber": "00123456",
"billable": "true"
},
"emergencyContactDetails": {
"emergencyContacCity": "KOOODC",
"emergencyContactNumber": "9412345678",
"emergencyContactPerson": "Moll Mathew",
"emergencyContactAddress": "KOOODC"
}
},
"billSubmissionMode": "manual",
"travelClass": "Economy",
"access_token": "",
"travelEndDate": "25-01-2016",
"timeStamp": "2015-12-11 16:00:47.395",
"travelType": "DTR",
"travelID": "3000553702",
"travelStartDate": "20-01-2016",
"approvalGIMS": "approvalGIMS",
"expenseCodes": {
"ExpenseTypeCollection": [{
"travelType": "DTR",
"client": "200",
"expenseDescription": "LODGING",
"glAccount": "0000834110",
"lastChangedBy": "",
"expenseCode": "DCN",
"changedOn": "0000-00-00",
"expenseStatus": "ACTIVE"
}, {
"travelType": "DTR",
"client": "200",
"expenseDescription": "BUSINESS",
"glAccount": "0000839301",
"lastChangedBy": "",
"expenseCode": "DMT",
"changedOn": "0000-00-00",
"expenseStatus": "ACTIVE"
}],
"ErrorCodeCollection": [{
"ErrorText": "S",
"ErrorType": "S"
}]
},
"empEmailID": "jaiseephen#gmail.com",
"entry_type": "new_entry",
"approvalBFM": "approverBFM",
"status": "Pending for Expense"
}],
"location_contextCollection": [{
"Status": "success"
}],
"user_context": {
"timeStamp": "2015-12-11 16:00:47.754",
"access_token": "",
"empID": "00123456",
"buDetailsCollection": [{
"buHeadADID": "",
"buHeadName": "",
"buHeadEmail": ""
}],
"empTechManager": {
"techMgrEmpID": "",
"techMgrADID": "",
"techMgrName": "",
"techMgrEmail": ""
},
"empPassportDetails": {
"endDate": "",
"dateOfBirthAsOfPassport": "0000-00-00",
},
"empDetails": {
"secondSupervisorEmpNumber": "00000000",
"empDOB": "15.05.1999",
},
"empEmailID": "jaiseephen#gmail.com",
"supDetailsCollection": [{
"ADID": "FAMM",
"supADID": "FAMM",
"supEmail": "fazee_ammed#gmail.com",
"lastName": "Faz Mammed",
"supCostCenter": "",
"Email": "fazee_ammed#gmail.com",
"CostCenter": "",
"empNumber": "00678444",
"supEmpID": "00678444",
"supName": "Faz Mammed",
"Name": "Faz Mammed"
}],
"altSupDetailsCollection": [{
"supADID": "FAMM",
"supEmail": "fazee_ammed#gmail.com",
"supEmpID": "00678444",
"supName": "Faz Mammed"
}]
}
}
}
I believe the simplest solution would be parse JSON.parse(text). Then, you can use that object in your Backbone model like this:
var obj = JSON.parse(income);
obj.EmployeeContext.travellContextCollection[0]
Also for finding a target value you can create function for searching target node.

Dynamically generated metadata does not display grid

The following data is being used to load and display a grid dynamically. The only difference between the two grids is that the first reader takes in the data below as is, but the second grid only knows about the data and the metaData will be generated on the fly. I placed stubs for the fields and columns as this is not the issue and I haven't decided on how I will generate the data yet.
Both of the readers eventually pass the data below to the JsonReader's readRecords()' function via this.callParent([data]);, but the second one does not display the data. The data is there, but I am not sure why it does not display?
There are two links to demos below. The first is a JSFiddle that loads from memory and the second is a Sencha Fiddle that loads through AJAX.
Snippet
var rawFields = [
{ "name": "year", "type": "int" },
{ "name": "standard", "type": "string" },
{ "name": "bitRate", "type": "float" }
];
var rawColumns = [
{ "text" : "Year", "dataIndex" : "year", "flex" : 1 },
{ "text" : "Standard", "dataIndex" : "standard", "flex" : 1 },
{ "text" : "Bit/Sec", "dataIndex" : "bitRate", "flex" : 1 }
];
Ext.define('Example.reader.DynamicReader', {
extend : 'Ext.data.reader.Json',
alias : 'reader.dynamicReader',
readRecords : function(data) {
var response = {
data: data,
metaData : this.createMetaData(data),
success: true
};
console.log(response);
return this.callParent([response]);
},
createMetaData : function(data) {
return {
idProperty : "id",
fields : rawFields, // These will eventually be generated...
columns : rawColumns // These will eventually be generated...
};
}
});
Data
{
"data": [
{
"id": 0,
"year": 1997,
"standard": "802.11",
"bitRate": 2000000
},
{
"id": 1,
"year": 1999,
"standard": "802.11b",
"bitRate": 11000000
},
{
"id": 2,
"year": 1999,
"standard": "802.11a",
"bitRate": 54000000
},
{
"id": 3,
"year": 2003,
"standard": "802.11g",
"bitRate": 54000000
},
{
"id": 4,
"year": 2007,
"standard": "802.11n",
"bitRate": 600000000
},
{
"id": 5,
"year": 2012,
"standard": "802.11ac",
"bitRate": 1000000000
}
],
"metaData": {
"idProperty": "id",
"fields": [
{
"name": "year",
"type": "int"
},
{
"name": "standard",
"type": "string"
},
{
"name": "bitRate",
"type": "float"
}
],
"columns": [
{
"text": "Year",
"dataIndex": "year",
"flex": 1
},
{
"text": "Standard",
"dataIndex": "standard",
"flex": 1
},
{
"text": "Bit/Sec",
"dataIndex": "bitRate",
"flex": 1
}
],
"success": true
}
}
Demos
The following examples both achieve the same thing, so the only difference is the loading of the data.
Loading from Memory
http://jsfiddle.net/MrPolywhirl/zy4z5z8a/
Loading from AJAX
https://fiddle.sencha.com/#fiddle/d3l
I figured out the answer. I needed to specify a root value for the reader so that the data can be mapped properly.
Ext.onReady(function() {
Ext.widget("dynamicGrid", {
title: 'WiFi LAN Data Rates [Dynamic]',
renderTo: Ext.get('example-grid-dynamic'),
readerType: 'dynamicReader',
// This need to match the 'data' key specified in the `response` object
// that was created in readRecords().
readerRoot: 'data',
data : rawData
});
});
The documentation for root notes that the root property has to map to the data portion of the response.
Documentation for Json.root:
Ext.data.reader.Json.root
root : String
The name of the property which contains the data items corresponding to the Model(s) for which this Reader is configured. For JSON reader it's a property name (or a dot-separated list of property names if the root is nested). For XML reader it's a CSS selector. For Array reader the root is not applicable since the data is assumed to be a single-level array of arrays.

Resources