Add empty row with message "No results found" - slickgrid

When there's no data I want SlickGrid to display a message that states something like "No results found". Any way of doing that? I can't find it in the docs.

In the end I hacked it a bit like the following (data is loaded via ajax following the example they have at "example6-ajax-loading.html"):
loader.onDataLoaded.subscribe(function (e, args) {
// check if there's any data in the data array
....
if (!anyData) {
grid.invalidateAllRows();
$('.grid-canvas').html('<div>No Data.</div>');
return;
}
}

Related

phonegap sqllite Database: the statement callback raised exception

i am having this strange "the statement callback raised an exception or error did not return false"
it is just a simple databases example.
my code is on github here:
https://github.com/prantikv/phonegapDBdemo
please read the comments in the code it explains everything.
i suspect the problem is in the ajax callbacks for the database.
if that is true than how can i make the ajax callback wait for data in sql-lite/phonegap?
function formSent(){//fired when form is submited
alert("formSent called");
db.transaction(queryDB, errorTrans);
return false;
}
function errorTrans(err){ //error for formsent
alert("formsent "+err.message+"|"+err.code);//error is generated here
}
function createSuccess(){//just alerts on success
alert("DB Created");
}
function populateDB(tx) {//transaction obj is passed. Table Created not populated
alert("populateDB called");
tx.executeSql('CREATE TABLE IF NOT EXISTS myDB (id , data)');
}
function onDeviceReady(){
db= window.openDatabase("Database", "1.0", "Display Name", 4*1024*1024);
db.transaction(populateDB, createERR, createSuccess);
}
function createERR(err){//error for create
alert("Create "+err.message);
}
AM i supposed to add return false for every database callback.if yes then which Boolean is to be returned when?
The phonegap doc examples dont have it http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Database
The error message usually isn't because of SQL, it is rather about exception that happens when you are executing callback for it. So you most probably have JS error happening.
I found
tx.executeSql('INSERT INTO myDB VALUES (?,?)', [username,email], insertSuccess, errorInsert);
on line 47 of index.js. It is lacking the (id,data) before VALUES. This causes the next SQL call
tx.executeSql('SELECT * FROM myDB', [], querySuccess, errorSelect);
to fail. Fix that and then try again.

Kendo DataSource Single-Row Read

I have a mobile app that receives a push notification, when it does, I know there is a row that that needs to be updated. I have tried two methods for retrieving just that one:
var row = data_source.get(<id>);
row.dirty = true;
data_source.sync();
This tries to fire an UPDATE, which I could shoe-horn into doing what I want, but it's conceptually wrong.
The other option that I have tried:
data_source.read( { id : <id> } );
Which fires off a READ request, with the ID in options.data. When I try to hook this up, kendo complains about not getting an array back, and when I make the response into an array, it doesn't seem to work either.
How am I supposed to do this? GET it outside the context of the DataSource, and set the relevant parts, and then set the dirty bit to false?
Kendo doesn't do single row read out of the box. If its not feasible to do full read(), you have to do what you proposed. Try following :
1) make your server side read method to accept requests with or without id, without to read all items, with to read your one row.
2) use parameter map together with isPushNotificaton flag to control the read request params
parameterMap: function(data, type) {
if (type == "read") {
if (isPushNotificaton)
return { id : yourId };
else
return { id : 0}; // get all
}
}
3) use requestEnd to decide how to deal with read result
requestEnd: function(e) {
var type = e.type;
if (e.type == 'read') {
// examine the response(by count/add additional flags into response object)
var isFullReadResponse = ...;
if (!isFullReadResponse) {
// DIY
e.preventDefault();
UpdateSingleRow(response, datasource.data());
}
}
}
4) Implement UpdateSingleRow method as you proposed - .."and set the relevant parts, and then set the dirty bit to false", (Refresh a single Kendo grid row)

Alert with jqGrid error messages

I would like to get an alert when errors occur when loading my jqGrid table. For instance, when the jsonReader is not well configured, like when repeatitems is true instead of false, U can see in Firebug the error:
ccur is undefined
[Break On This Error] idr = ccur[idn] || idr;
How can I place such an error in an alert? I have already tried using loadError, but it doesn't work, because it is not even triggered.
It seems for me that you should just use try - catch block over jqGrid code:
try {
// create the grid
$("#list").jqGrid({
// all jqGrid options
});
} catch (err) {
// display the error message which you want
alert(err);
}
UPDATED: You are right, the try {...} catch (err) {...} which I described before work in IE only with reading local data. In case of getting data from the server the exception take place inside of success callback of $.ajax. To be exactly it take place inside of addJSONData or addXmlData depend of the type of data which you use. To catch the exception you should modify code of jqGrid in the place. The modified code can be about the following
success:function(data,st, xhr) {
if ($.isFunction(ts.p.beforeProcessing)) {
ts.p.beforeProcessing.call(ts, data, st, xhr);
}
try {
if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
if(lc) { lc.call(ts,data); }
if (pvis) { ts.grid.populateVisible(); }
} catch (err) {
alert(err);
}
if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
data=null;
if (npage === 1) { endReq(); }
}
I tested in the demo the corresponding modified version of jquery.jqGrid.src.js which display error message. I don't reproduced exactly the error which you described so the error message is a little other as in your case.
If you need minimized version of the modified jquery.jqGrid.src.js file you can produce it yourself with any JavaScript minimizer. For example Microsoft Ajax Minifier can be free downloaded and installed. The usage as
ajaxmin.exe jquery.jqGrid.src.js -out jquery.jqGrid.min.js
will produce the new minimized version of jquery.jqGrid.src.js which will be even a little smaller as the original jquery.jqGrid.min.js.
Another good minimizer is available online here. You should use "Simple" Optimization only.

Extjs store.on('save', afterSave(resp));

I have a simple ExtJs (3.4) Grid with a Writer. When the user makes some changes the store is saved to the server as follows:
store.on('save', afterSave(resp));
All is fine. However, I want to get a response as to wheather the record has been saved successfully, failed or an update conflict happed. How to best do this?
Are you using Ext.data.proxy.Ajax to load your stores? If so, you can use the reader property to evaluate and handle the server responses.
Another option would be to make AJAX called directly and handle the responses from there as well
I used exception listener to parse the data as suggested here. But, is this the right way to do this.
Ext.data.DataProxy.addListener('exception', function(proxy, type, action,
options, res) {
if (type == 'response') {
var success = Ext.util.JSON.decode(res.responseText).success;
if (success) {
console.log('UPDATE OK');
} else {
console.log('UPDATE FAILED');
}
}
});

Calling multiple views in CouchApp query

I need to search the CouchDB based on several criteria entered in a form. Name, an array of Tags and so on. I would then need various views to index on these fields. Ultimately, all the results will be collated in data.js and provided to mustache.html. Say there are 3 views - docsByName, docsByTags, docsById.
What I don't know is, how to query all these views in query.js. Can this be done and how ?
Or should the approach be of that to write one view that makes multiple emits for each search somehow ?
Thank you.
From what you say I assume you are using Evently, so I will quote from Evently primer:
The async function is the main star, which in this case makes an Ajax request (but it can do anything it wants). Another important thing to note is that the first argument to the async function is a callback which you use to tell Evently when you are done with your asynchronous action. [...] Whatever you pass to the callback function then becomes the first item passed to the data function.
In short: put your Ajax requests in async.js.
As a side note: Evently is only one of the possible choices to write a couchapp and it is not clear if it is maintained. However it works and it is easy to rearrange the code to not use it.
EDIT: here is a sample async function (cut&paste from an old program):
function(cb, e) {
var app = $$(this).app
;
app.db.openDoc('SOMEDOCID', {
error: function(code, error, reason) {
alert("Error("+code+" "+error+"): "+reason);
}
, success: function(doc) {
app.view('SOMEVIEWNAME', {
include_docs: true
, error: function(code, error, reason) {
alert("Error("+code+" "+error+"): "+reason);
}
, success: function(resp) {
resp.doc = doc;
cb(resp);
}
});
}
});
}

Resources