one column having string data and check box in extjs4.1 - html

in my grid,i should have the ability to have check boxes and String data based on the statuses returned from the webservice.Now i am writing custom renderer function given below :
function customcolumn1(value, metadata, record) {
var completedTime = record.get('nccompletedTime');
var completedByLastName = record.get('nccompletedByLastName');
var completedByFirstName = record.get('nccompletedByFirstName');
if (value == 'Completed') {
return completedTime + " " + completedByLastName + "," + completedByFirstName;
} else if (value == 'Pending') {
return "<input type='checkbox' disabled>";
} else if (value == 'Assigned') {
return "<input type='checkbox'>";
}
}
And the grid is
var SAFjobgrid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{
text: "",
width: 30,
renderer: customSeqNumber,
dataIndex: 'sequenceNumber'},
{
text: "Task",
width: 350,
renderer: customTask,
dataIndex: 'label'},
{
text: "Complete",
width: 160,
renderer: customcolumn2,
dataIndex: 'stampActionStatus'},
{
text: "Verified",
width: 160,
renderer: customcolumn,
dataIndex: 'verifyActionStatus'},
{
text: "Non Compliance",
flex: 1,
renderer: customcolumn1,
dataIndex: 'ncActionStatus'}
]
});
Now i want to check the check boxes and capture the stampIds for those records.And when i click on update button which is oustside of the grid,i should be able to call the webservice with the captured stampId's.I tried to put onclick event on checkbox while returning from the renderer function.But how should i access the stampId for that record.if i select multiple checkboxes,multiple stampid's should go to webservice and if i uncheck the checkbox,the corresponding stampid should be removed from stampId's.
Could anyone help on this one..

You can look at CheckColumn user extension http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ux.CheckColumn But in your case you have to override renderer method like this
renderer : function(value, meta, record){
var cssPrefix = Ext.baseCSSPrefix,
cls = [cssPrefix + 'grid-checkheader'],
completedTime = record.get('nccompletedTime'),
completedByLastName = record.get('nccompletedByLastName'),
completedByFirstName = record.get('nccompletedByFirstName');
if (value == 'Completed') {
//render string instead of checkbox
return Ext.String.format('{0} {1},{2}', completedTime, completedByLastName, completedByFirstName);
}
if (value === 'Assigned') {
cls.push(cssPrefix + 'grid-checkheader-checked');
}
//render checkbox stub,
//it is actually a div element with special css classes to simulate checkbox
return '<div class="' + cls.join(' ') + '"> </div>';
}
To collect al checked/unchecked rows you can use this store method http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.AbstractStore-method-getUpdatedRecords
It returns array of models which were updated by checking/unchecking this column

Related

How to get data event click in angular google chart-angular 2+

I used the google charts in my angular project dashboard.
By reading the document: https://github.com/FERNman/angular-google-charts , I used the below code for getting the event(which should contain the elements of the chart which I selected)
As per the document, the select event is emitted when an element in the chart gets selected.
<google-chart (select)="onSelect($event)"></google-chart>
I used the same in my code.
Html:`
<google-chart #chart [title]="Bartitle" [type]="Bartype" [data]="Bardata" [columnNames]="BarcolumnNames"
[options]="Baroptions" [width]="Barwidth" [height]="Barheight"
(select)="onSelect($event)">
</google-chart>`
Component.Ts
this.Bartitle = 'Current and Target';
this.Bartype = 'BarChart';
this.Bardata = [
["2012", 900, 390],
["2013", 1000, 400],
["2014", 1170, 440],
["2015", 1250, 480],
["2016", 1530, 540]
];
this.BarcolumnNames = ["Year", "Current", "Target"];
this.Baroptions = {
hAxis: {
title: 'Maturity'
},
vAxis: {
title: 'Month'
},
};
this.Barwidth = 200;
this.Barheight = 200;
onSelect(event) {
console.log(event);
}
But I dont get the values which I selected..
I need the values of maturity and the year... How i get that?? Did I made any changes??
Select
The select event is emitted when an element in the chart gets selected.
<google-chart (select)="onSelect($event)"></google-chart>
The event of type ChartSelectionChangedEvent containing an array of selected values.
in component
EDIT : Based on comments
onSelect(event) {
const { row, column } = event[0];
const year = this.Bardata[row][0];
let selectedItem;
if (column === 1) {
selectedItem = "current";
}
if (column === 2) {
selectedItem = "target";
}
console.log("year", year, "SelectedItem" ,selectedItem, this.Bardata[row][column]);
}
for more info read the documentation :
https://github.com/FERNman/angular-google-charts

ag-Grid - Is it possible to create a floating menu for each row?

I'm trying to create a menu that appears when a user hovers on a row, just like in the image below.
I did not find any built-in option to achieve this. Also tried using a custom CellRenderer function to create an element that I could move around later, but that didn't work as expected since it presented some other challenges (css wise) and was not really achieving the goal.
Is there a way to build this kind of menus in ag-Grid?
To work around the problem, you could use onCellMouseOver & onCellMouseOut methods:
var gridOptions = {
columnDefs: columnDefs,
onCellMouseOver : onCellMouseOver,
onCellMouseOut: onCellMouseOut,
...
};
Define both functions:
var onCellMouseOver = function(event){
//Get current row
var rowIndex = event.node.rowIndex;
var row = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
//Set current row as not selected - in order to base on 'cellStyle' function
row.setSelected(true);
//Setup refresh params
var params = {
force: true, //Force refresh as cell value didn't change
rowNodes: [row]
};
//Refresh current row cells
gridOptions.api.refreshCells(params);
}
var onCellMouseOut = function(event){
//Get current row
var rowIndex = event.node.rowIndex;
var row = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
//Set current row as not selected - in order to base on 'cellStyle' function
row.setSelected(false);
//Setup refresh params
var params = {
force: true, //Force refresh as cell value didn't change
rowNodes: [row]
};
Then define 'cellStyle' function for your column:
var columnDefs = [
{headerName: "your_column_name", field: "your_column",
cellStyle: function(params) {;
console.log('Is row selected', params.node.selected);
if (params.node.selected) {
return {display : 'none'};
} else {
return {display : 'inherit'};
}
}
}
];
You can find more about data refresh here: https://www.ag-grid.com/javascript-grid-refresh/
The full implementation of the code above might be found here: Working example
Second solution, edited after comments:
Another way is to use css classes to achieve the result.
{
headerName: "Price",
field: "price",
cellStyle: { "text-align": "center" },
cellRenderer: function(params) {
return (
"<div class='buttons'>" +
"<div class='back'>" +
params.value +
"</div>" +
"<div class='front'><button>Option A</button><button>Option B</button></div>" +
"</div>"
);
}
Buttons are shown on hover based on .ag-row-hover ag-grid class:
.front {
display: none;
}
.ag-row-hover .front {
display: inherit;
}
Working example

Is there a way to retrieve all editable cells from kendo grid?

I have a kendo grid in which fields are editable based on some condition like:
//var isEditable= some condition
fields: {
Id: { type: "int", editable: false },
Amount: {type: "number", editable: isEditable},
}
I want to get all editable cells and perforn something on them before they are displayed.
Currently i'm using dataBound event iterate rows and cells and find desired cells
dataBound: function(e){
var rows = e.sender.tbody.children();
for (var j = 0; j < rows.length; j++) {
var row = $(rows[j]);
if (isEditable){
var cell1 = row.children().eq("hardcoded index");
var cell2 = row.children().eq("hardcoded index 2");
var cell3 = row.children().eq("hardcoded index 3");
......
......
// perform action
}
}
Is there a better approach to achieve that?
Since you want to do something to the editable element before display, I would use a template to accomplish that. Here is an example that turns the background color red if the Amount field is editable:
<script id="editableTemplate" type="text/x-kendo-template">
#if (Editable) { #
<div style='background-color:red'>#=Amount#</div>
# } else { #
<div>#=Amount#</div>
# } #
<script>
Another way to approach this is to take parameters by wrapping the template in a function:
function foo(isEdit, value) {
if(isEdit){
return "<div style='background-color:red'>" + value + "</div>";
} else {
return "<div>" + value + "</div>";
}
}
You can then set the column template as:
{
field: "Amount",
type: "number",
template: function(data) {
return kendo.template("#=foo(isEditable, Amount)#")
},
editable: isEditable
}
Here is a basic fiddle.

Google Visualization Column Chart set a data column from query as role: "Style"

I have a Google Visualization Column Chart from a query that works fine. I can set the a columns with a style role after the query by using the code snippet below. It adds a new column to the query data and sets the role as "Style". This colors each of the column chart bars accordingly. But I want to be able to use one of my query columns "C" for example as the color code and not have to add it afterward. I can't seem to get this to work. Any ideas? I posted more of my code below the snippet so you can see where I'm coming from. Thanks so much guys for any help you can give. Brandon
var data = response.getDataTable();
data.addColumn({type: "string", role: "style" });
data.setCell(0,2,'red');
data.setCell(1,2,'orange');
data.setCell(2,2,'green');
data.setCell(3,2,'yellow');
// More code above this, but I ommited it.
function drawDashboard() {
var query = new google.visualization.Query(
'URL');
query.setQuery('SELECT A, B, C');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
data.addColumn({type: "string", role: "style" });
data.setCell(0,2,'red');
data.setCell(1,2,'orange');
data.setCell(2,2,'green');
data.setCell(3,2,'yellow');
// Create a dashboard.
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var scoreSlider = new google.visualization.ControlWrapper({
controlType: 'NumberRangeFilter',
containerId: 'filter_div',
options: {
filterColumnLabel: 'Class AVG'
}
});
var ClassFilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'Classfilter_div',
options: {
'filterColumnLabel': 'Teacher Name','ui': { 'labelStacking': 'veClasscal','allowTyping': true,'allowMultiple': true
}
}});
// Create a Column Bar chart, passing some options
var columnChart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
options: {
title: 'Math Proficiency by Class',
height: 320,
width: 500,
chartArea:{left:"10%",top:"10%",width:"80%",height:"60%"},
hAxis: {textStyle: {fontSize:14}, title: 'Teacher Name', titleTextStyle: {fontSize:14}, textStyle: {fontSize:14}},
vAxis: {minValue: 0, maxValue: 100, title: 'Math Proficiency AVG', titleTextStyle: {fontSize:14}, textStyle: {fontSize:14}},
legend: {position: 'none'},
animation: {duration:1500, easing:'out'},
colors: ['#a4c2f4','#3c78d8']
},
view: {columns: [0, 1, 2]}
});
// Define a table
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
dataTable: data,
containerId: 'table_div',
options: {
width: '400px'
},
view: {columns: [0, 1,]}
});
// Establish dependencies, declaring that 'filter' drives 'ColumnChart',
// so that the column chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind([scoreSlider], [table, columnChart]);
dashboard.bind([ClassFilter], [table, columnChart]);
// Draw the dashboard.
dashboard.draw(data);
}// More code below this, but I ommited it.
I'm not sure how you would add this to a column in the query but...
using a DataView with a calculated column should work...
Assumes the value you want to test is in the second column -- index 1
var data = response.getDataTable();
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
type: "string",
role: "style",
calc: function (dataTable, rowIndex) {
if (dataTable.getValue(rowIndex, 1) < 0.69) {
return 'color: red;';
} else if ((dataTable.getValue(rowIndex, 1) >= 0.69) && (dataTable.getValue(rowIndex, 1) <= 0.79)) {
return 'color: yellow;';
} else {
return 'color: green;';
}
}
}]);

Apploop through events in json feed

I see a lot of event objects when I use the alert after the ajax post success in my jquery below.
How I can access the details for each event and change them accordingly?
eventSources: [
{
url: 'json-events.php',
type: 'POST',
error: function (data) {
alert('there was an error while fetching events!' + data.msge);
},
success: function (data) {
alert(data);
// how do i loop through the event objects and filter which ones are approved == 1?
if(data.approved == "1") {
// How do I then change the properties of each event that is approved?
event.title = title + "approved";
event.Color = 'green';
var event.className = "approved";
} else{
var event.title = title + "awaiting approval";
event.Color = 'red';
var event.className = "unapproved";
}
}
}]
Update: change color of single event once approved
// approve function
$('.approve').click(function (calEvent, jsEvent, view, getid) {
// Get id of event
var getid = $('.approve').attr('id');
if ($(this).html() == "yes") {
// AJAX post to insert into DB
$.post("ajax.php", {
action: 'approve',
color: 'green'
},
function (data) {
var fancyContent = ('<div class="header"><p>' + data.msge + '</p></div>');
$.fancybox({
content: fancyContent
});
}, "json");
// get event
var eventObject = $('#calendar').fullCalendar( 'clientEvents', getid );
// set event colors
eventObject.backgroundColor = 'green';
eventObject.eventBorderColor = 'green';
eventObject.title = event.title + " approved";
// update event somehow?
$('#calendar').fullCalendar('updateEvent', eventObject);
} else {
// close fancybox
$.fancybox.close();
} // end of if
}); // end of approve click
You can loop through you JSON response like this:
success : function( responseData ) {
$.each( function( index, responseObj ) {
if( responseObj.approved === "1" ) {
responseObj.title += " approved";
responseObj.className = "approved";
}
else {
responseObj.title += " waiting approval";
responseObj.className = "unapproved";
}
} );
}
You will not be able to set the color of each event type using this style of filtering.
You could break up each type into their own event sources, something like:
eventSources : [
{
url : 'json-events.php?approved=y',
color : 'green'
// ... success() and other attributes go here
},
{
url : 'json-events.php?approved=n',
color : 'red'
// ... success() and other attributes go here
}
]