jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Substring or get a selected value in cellsrenderer:function
This topic contains 7 replies, has 3 voices, and was last updated by Gecko 11 years, 7 months ago.
-
Author
-
Am checking a condition in the cellsrenderer function where i need to substring the value. Can you please suggest me how to do it? Here is the code of what am trying to do.
cellsrenderer:
function (row, column,value,data ) {
//Start:This snippet is added to rectify the milestone empty date issue. If a date is selected, there was no way to unselect a date or make the date empty
//if(value==’Thu Jan 1 05:30:00 UTC+0530 1970′){
alert(value.charCodeAt(0));
if
(value==‘Thu Jan 1 05:30:00 UTC+0530 1970’ || value==‘Wed Dec 31 16:00:00 PST 1969’ ){
return
‘<div> </div>’;
}
}
}In the above code am checking a condition for VALUE. but i just need to check whether the string contains 1970 instead of the entire ‘Thu Jan 1 05:30:00 UTC+0530 1970’. Please let me know how to do that.
Is it possible to do it or not?? please do reply..
Hi Akshar,
For checking whether a string is contained within a string, you may use “indexOF” – http://www.w3schools.com/jsref/jsref_indexof.asp
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHello Peter,
If i use any of the JQuery or javascript functions like indexOf, jQuery :contains() Selector or substr it gives a javascript error. And the error isSCRIPT438: Object doesn't support property or method 'indexOf' jqxgrid.js, line 7 character 103889
Hi Akshar,
Not sure how you use indexOf as it is a JavaScript function of the String. In addition, “cellsrenderer” should return HTML.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comcellsrenderer:function (row, column,value,data ) {var date = value.indexOf("1970");alert(date);if(date != -1){return '<div> </div>';}} },
This is how i have used. Am i doing something wrong???
Hi Akshar,
It is possible the value to be a Date or Number object. As I already written, indexOf is method of the String object so you need to first convert the value to String and then use indexOf.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comAkshar,
Following Peters’ instructions please try thiscellsrenderer:function (row, column,value,data ) { var date = value.toString().indexOf("1970"); alert (date); if(date !== -1){ return '<div> </div>'; }}
or this (which is a little cleaner)
cellsrenderer:function (row, column,value,data ) { if(value.toString().indexOf("1970")!== -1){ return '<div> </div>'; }}
-
AuthorPosts
You must be logged in to reply to this topic.