onClick function of button that is in a datagrid row - extjs - datagrid

I have put a button on a dataGrid with the following code
column is;
var avaliableAction = {
header : "Action",
width : 120,
sortable : true,
align : "left",
dataIndex : 'status',
renderer : statusRenderer
};
data grid is;
var mainJobsGrid = new Ext.grid.GridPanel({
store : jobsStore,
columns : [ avaliableAction ],
viewConfig : {
forcefit : true
},
title : 'Data Mart Jobs',
height : 198,
width : 540,
frame : true
});
renderer is;
function statusRenderer(value, id, r) {
var START_ICON = '/etlscheduler/resources/images/start-icon.png';
var STOP_ICON = '/etlscheduler/resources/images/stop-icon.png';
if (value == "STOPPED") {
return "<input type='button' class='btnStart' onClick='doStart(); '>";
} else if (value == "RUNNING" || value == "WAITING") {
return "<input type='button' class='btnStop' onClick='doStop();'>";
}
};
and
function doStop() { ... }
function doStart() { ... }
The problem is that when I click the button exception occurs as "doStop is not defined"

seems like you need to define the function
function doStop() { ... }

I faced the same problem, and it wasn't a typo! i have noticed that the implementation of the called function works only if it was outside the "Ext.onReady(function(){}".
If someone faces the same problem, i have solved it through writing the function as following:
Ext.the_function = function(){...}
instead of :
var the_function = function(){...}
This would fix the problem and it will work wherever you put it!

Related

ExtJS : move a record in a grid

I have a simple grid on ExtJS and would like the user to be able to move the record from its original position.
When the user double clicks on a record, a small window containing a combobox appears, he can choose a value on the combobox and then click the save button to apply the change.
However, it doesn't work, I've searched many solutions for this on different forums and none seems to work. Either nothing happens, or an undefined row is added at the end of the grid. Here is the base code I use :
onEditRank: function(view, cell, cellIndex, record, row, rowIndex, e)
{
var reditor = Ext.create('CMS.view.Views.RankEditor', {id: 'reditorView'});
var form = reditor.down('form');
var oldPos = this.getFlatrq().getView().indexOf(record);
var grStore = this.getGridRnkStoreStore();
var i;
var data = [];
for(i = 1; i <= CMS.global.Variables.limit + 1; i++)
{
data.push(i);
}
var combo = Ext.create
(
'Ext.form.field.ComboBox',
{
fieldLabel: 'Rank',
itemId: 'cmbRank',
store: data
}
);
var saveRnk = Ext.create
(
'Ext.button.Button',
{
text: 'Save',
handler: function()
{
}
}
);
form.add(combo);
form.add(saveRnk);
reditor.show();
}
Now here are the different handlers I have tried for my save button :
handler: function()
{
grStore.remove(record);
grStore.insert(record, combo.getValue() - 1);
this.up('form').up('window').close();
}
handler: function()
{
grStore.removeAt(oldPos);
grStore.insert(record, combo.getValue() - 1);
this.up('form').up('window').close();
}
handler: function()
{
var rec = grStore.getAt(oldPos).copy();
grStore.removeAt(oldPos);
grStore.insert(rec, combo.getValue() - 1);
this.up('form').up('window').close();
}
Those 3 handlers inserted undefined rows at the end of my grid. I displayed the values of oldPos and combo.getValue() and they are correct, I also displayed the record variable before and after the remove because I thought it might be destroyed but it wasn't. I have also tried to add a move function to store and call it :
'CMS.store.GridRnkStore',
{
extend: 'Ext.data.Store',
model: 'CMS.model.GridRnkModel',
autoLoad: false,
filterOnLoad: true,
autoSync: true,
move: function(from, to)
{
console.log(from + " " + to);
var r = this.getAt(from);
this.data.removeAt(from);
this.data.insert(to, r);
this.fireEvent("move", this, from, to);
},
}
);
But it didn't work either, it did nothing actually (I put some console.log in the move function to see if it was called and it was, with the right parameters). I'm running out of ideas, any help would be appreciated.
Thank you.
try to set the private move parameter to true of store.remove():
remove: function(records, /* private */ isMove, silent)

How to delete record from grid on delete in extjs4

I am working in extjs4. I have view with grid as item with code:
{
margin : '10 0 5 100',
xtype : 'grid',
id : 'g3',
//title : 'Educational Details',
store:'qb.qbquestionoptionStore',
columns : [ {
text : 'questionId',
dataIndex : 'questionId',
flex : 1
},
{
text : 'category',
dataIndex : 'category',
flex : 1
}, {
text : 'Answer',
dataIndex : 'isAnswer',
flex : 2.5
},
{
header : 'Remove',
renderer : function(val) {
return 'Remove';
},
}
So on clicking on remove link,corresponding entry gets deleted from database. But grid is still showing that deleted entry. In controller I have code for it as-
deleterow:function(cmp)
{
cmp.mon(cmp.getEl(),'click',function(event,target)
{
if(target.id=='remove')
{
// alert("hello");
listview=Ext.getCmp('g3');
listview.on({
itemClick: function(dv, record, item, index, e,opts)
{
liststore=this.getStore('qb.qbquestioncomplexityStore').sync();
liststore.load({
params:{
id:record.data.id,
questionId:record.data.questionId
}
});
console.log(record);
console.log(" Id is "+record.data.id);
var shopCart=Ext.create('Balaee.model.qb.qbquestioncomplexityModel',
{
id:record.data.id,
questionId:record.data.questionId
});
Ext.Msg.confirm('Confirm to delete', 'Want to delete record?', function (button)
{
if (button == 'yes')
{
shopCart.destroy();
}
}); }
}); }
},this,{delegate:"a"});
},
So how to delete record from grid?.
to remove a row from gridpanel, i do something like this:
var selectedRecord = grid.getSelectionModel().getSelection()[0];
grid.getStore().each(function(rec) {
if (rec == selectedRecord) {
grid.store.remove(rec);
}
});
grid.getView().refresh();
Your code is a bit weird but I think you are nearly there:
The easiest way is when you have set a proxy to the model. You just need to call destroy(). Any stores this record is bound to will be notified.
if (button == 'yes'){
record.destroy();
shopCart.destroy();
}
If not I assume for this example that your record is only bound to one store, then you can do it like
if (button == 'yes'){
var s = record.store;
s.remove(record);
s.store.sync();
shopCart.destroy();
}

nvd3.js : no mouseover datapoint effects in a line chart

I'm trying to draw a simple line chart using nvd3/d3. The transition that occurs on the datapoints during 'mouseover' are not visisble. How to fix this?.
adding the code below:
Date.prototype.addHours = function(h) {
this.setHours(this.getHours() + h);
return this;
};
function getData(transport) {
var arr = [];
for (var i = 0; i < transport.length; i++) {
arr.push({
x : new Date(transport[i].timePeriod).addHours(7),
y : transport[i].number
});
}
return arr;
}
function cumulativeTestData(transport) {
return [{
key : "Active Customers",
values : getData(transport),
color : "#ff7f0e"
}];
}
nv.addGraph(function() {
var chart;
chart = nv.models.lineChart().x(function(d) {
return d.x;
}).y(function(d) {
return d.y;
});
chart.xAxis.tickFormat(function(d) {
return d3.time.format("%d-%m-%y")(new Date(d));
});
chart.yAxis.tickFormat(d3.format(',g'));
d3.select('#chart1 svg').datum(cumulativeTestData(transport))
// .transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) {
nv.log('New State:', JSON.stringify(e));
});
return chart;
});
$(function() {
$("#day").click(function() {
var from = $("#from").val();
var to = $("#to").val();
$.ajax({
url : "http://api.local/api/GraphData?startDate=" + from + "&endDate=" + to,
type : 'GET',
contentType : "application/javascript",
crossDomain : true,
dataType : "jsonp",
cache : false,
async : false,
success : function(transport) {
// nv.addGraph(drawGraph(transport));
drawGraph(transport);
},
error : function() {
alert("failed in calling status");
}
});
});
});
If i run this code separately, i can see the data points but as I have to include this graph with many other controls, data points doesnt seem to be working.
also want to add that when i click on a particular data point on the line chart, i see this error in the console of fire bug
Error: Invalid value for attribute cx="NaN"
You might have to change the your JSON structure so either number becomes y and timePeriod becomes x , so its can be accessible by data that is been passed into the lineChart():
chart = nv.models.lineChart().x(function(d) {
return d.x;
}).y(function(d) {
return d.y;
});
If you are using :
chart.xAxis.tickFormat(function(d) {
return d3.time.format("%d-%m-%y")(new Date(d));
});
the date should be returned in UNIX TIME STAMP FORMAT. If you are NOT sending a UNIX TIME STAMP just use chart.xAxis.tickFormat().
I have a sample code running in a fiddle just have a look.
Finally you need a data structure similar to this.
data = [{
"values" : [{
"x" : 1025409600000,
"y" : 0
}, {
"x" : 1028088000000,
"y" : 0.09983341664682815
}, {
"x" : 1030766400000,
"y" : 0.19866933079506122
}, {
"x" : 1033358400000,
"y" : 0.29552020666133955
}, {
"x" : 1036040400000,
"y" : 0.3894183423086505
}],
"key" : "Line 1",
"color" : "#ff7f0e"
}, {
"values" : [{
"x" : 1025409600000,
"y" : 0.5
}, {
"x" : 1028088000000,
"y" : 0.4975020826390129
}, {
"x" : 1030766400000,
"y" : 0.4900332889206208
}, {
"x" : 1033358400000,
"y" : 0.477668244562803
}, {
"x" : 1036040400000,
"y" : 0.46053049700144255
}],
"key" : "Line 2",
"color" : "#2ca02c"
}]
Hope it helps.

Unique Dropdownlist is coming for the first page values in Jqgrid

Hello Every One!!!
I added codes for getting unique dropdownlist in the columns of jqgrid .
Dropdownlist is coming but it is coming for the first page of the jqgrid means that dropdownlist has the unique values of the first page of the jqgrid whereas i need all the unique values of the whole Jqgrid..
Below I am posting my codes...
grid = $("#gridId");
getUniqueNames = function (columnName) {
var texts = grid.jqGrid('getCol', columnName), uniqueTexts = [],
textsLength = texts.length, text, textsMap = {}, i;
for (i = 0; i < textsLength; i++) {
text = texts[i];
if (text !== undefined && textsMap[text] === undefined) {
// to test whether the texts is unique we place it in the map.
textsMap[text] = true;
uniqueTexts.push(text);
}
}
return uniqueTexts;
},
buildSearchSelect = function (uniqueNames) {
var values = ":All";
$.each(uniqueNames, function () {
values += ";" + this + ":" + this;
});
return values;
},
setSearchSelect = function (columnName) {
grid.jqGrid('setColProp', columnName,
{
stype: 'select',
searchoptions: {
value: buildSearchSelect(getUniqueNames(columnName)),
sopt: ['eq']
}
}
);
};
This function i have called like this...
setSearchSelect('extension');
grid.jqGrid('setColProp', 'Name',
{
searchoptions: {
sopt: ['cn'],
dataInit: function (elem) {
$(elem).autocomplete({
source: getUniqueNames('Name'),
delay: 0,
minLength: 0
});
}
}
});
setSearchSelect('username');
grid.jqGrid('setColProp', 'Name',
{
searchoptions: {
sopt: ['cn'],
dataInit: function (elem) {
$(elem).autocomplete({
source: getUniqueNames('Name'),
delay: 0,
minLength: 0
});
}
}
});
In between these two code snippets I am loading data into jqgrid locally using Ajax call.
Any help will be heartely appreciated..
Thanx in advance..
I belive getCol will return only currently loaded data from jqgrid (for defined column).
Because at first you load just first page, autocomplete has no way of knowing unique values of column for more than that!
You will have to either load all pages at once (small dataset) or
fill autocomplete from database.

adding button returns [object][object] in EXTJS

Am having a controller which basically calls a message window that is displayed for a few seconds. Am trying to add a button to this message window, but its returning [object][object].
Controller
success : function(response) {
this.mWin = Ext.create('App.view.GenMessage');
this.mWin.addMessage(true, LANG.SUCT, LANG.SUCTxt1);
}
View
Ext.define('App.view.GenMessage', {
extend : 'Ext.panel.Panel',
alias : 'widget.genmessage',
initComponent : function() {
this.msgCt = App.genMsgCt
this.msgCt.setWidth(300);
},
addMessage : function(status, title, msg) {
if (status == false) {
delay = 3000;
} else {
delay = 2000;
}
Ext.DomHelper.append(this.msgCt, {
html : this.buildMessageBox(status, title, msg)
}, true).slideIn('t').pause(delay).ghost("t", {
remove : false
});
},
/*
* buildMessageBox
*/
buildMessageBox : function(status, title, msg) {
console.log('buildMesssage');
switch (status) {
case true :
var icon = GENHTML.tick;
break;
case false :
var icon = GENHTML.warning;
break;
}
return ['<div class="genMsgDiv">', icon,
'<div class="genMsgHd leftMargin">', title,
'</div><div class="H3 leftMargin">', msg,
'</div></div>'].join('');
}
What i did was declare a button like
var button={
id: 'button1',
text :'Button1'
}
and then add to the div class mentioned above and return
['<div class="genMsgDiv">', button].join();
But, what i see in the screen is [object][object] in place of the button.
Could anyone please tell me what am doing wrong here. Is this the correct way to add the button
EDIT
Since we cannot add a button to a div, i tried doing
var config = Ext.create(Ext.panel.Panel, {
itemId : 'GENMSGPANEL',
height : 150,
cls : 'msg effect1',
border : false,
html : '<div class="genMsgDiv">' + icon +
'<div class="genMsgHd leftMargin">'+ title +
'</div><div class="H3 leftMargin">'+ msg +
'</div></div>',
items : [{
xtype : 'panel',
//cls : 'winTitle',
}, {
xtype : 'form',
itemId : 'GENMSGFORM',
border : false,
title : '',
buttonAlign : 'center',
fieldDefaults : {
msgTarget : 'side',
labelWidth : 110,
size : 30
},
buttons : [{
text : LANG.BTYES,
iconCls : 'icon-tick-tb',
iconAlign : 'right',
cls : 'tip-btn',
action : 'genDelete',
id : 'BTYES'
}, {
text : LANG.BTNO,
iconCls : 'icon-cross-tb',
iconAlign : 'right',
cls : 'tip-btn',
action : 'notDelete',
id : 'BTNO'
}]
}]
});
return config;
But, even this did not return anything
The answer is simple: You cannot add a ExtJS Button into the html config property of a component. This one is just for plain html. ExtJS objects belongs into the items array.
Decide to place your html content into a box (xtype for component) and add this to the items array. Then you can add your button. Don't use the html at all in your case.
You may change/set any required classes. Please note that I haven't check the way you manipulate the DOM.
// you may use a layout to align them
items : [
{
xtype: 'box',
cls : 'msg effect1',
html : '<div class="genMsgDiv">' + icon +
'<div class="genMsgHd leftMargin">'+ title +
'</div><div class="H3 leftMargin">'+ msg +
'</div></div>'
},
{
xtype : 'panel',
//cls : 'winTitle',
},
...

Resources