You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by rosecorp <ro...@gmail.com> on 2013/01/20 14:11:36 UTC

datatable ajax with new column

Hello All,

I am using datatables component in similar way which was presented here:

http://tapestry5-jquery.com/other/datatableajaxwithnewcolumn but I am
getting sam exception. I have updated datatables to the newest version but
it didn't help. Do you know what is causing this problem?

Many thanks for any answer.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/datatable-ajax-with-new-column-tp5719395.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: datatable ajax with new column

Posted by rosecorp <ro...@gmail.com>.
Ok Guys, I have fixed it

OverrideDataTableModel:


/**
	 * methdo returning the desired data
	 */
	public JSONObject getResponse(GridDataSource source){
		
		response.put("sEcho", request.getParameter(DataTableConstants.ECHO));
		
		int records = source.getAvailableRows();
	    
		response.put("iTotalDisplayRecords", records);  
	    
		response.put("iTotalRecords", records);
	    
	    String displayStart =
request.getParameter(DataTableConstants.DISPLAY_START);
	     int startIndex=Integer.parseInt(displayStart);
	     
	     String displayLength =
request.getParameter(DataTableConstants.DISPLAY_LENGTH);
	     
	     int rowsPerPage=Integer.parseInt(displayLength);
	     
	     int endIndex= startIndex + rowsPerPage -1;
	     if(endIndex>records-1) endIndex= records-1;
	     source.prepare(startIndex,endIndex,sortModel.getSortConstraints() );
	     
	     
	     JSONArray rows = new JSONArray();
	     
	     for(int index=startIndex;index<=endIndex;index++)
	     {	 
	    	 JSONObject cell = new JSONObject();
	    	 
	    	 Celebrity obj = (Celebrity) source.getRowValue(index);
	    	 
	    	 List<String> names = model.getPropertyNames();
	    	 
	    	 for (String name: names)
	    	 {
	    		 Object val;

	    		 if(name.equals("view")){
	    			 //We add the content of the extra column
	    			 
	    			 //We use the ComponentResources service, for creating an EventLink
	    			 //We will add the id of the current element as a context of the
event link
	    			 val = String.format(" Update <%s> 
",linkSource.createPageRenderLinkWithContext(DataTableAjaxWithNewColumn.class,obj.getId()).toURI());
	    					 
	    		 }
	    		 else {
	    			 PropertyConduit conduit = model.get(name).getConduit();
	    			 String cellValue;
		    		 Class type = conduit.getPropertyType();
		    		 
		    		 val = conduit.get(obj) != null ? conduit.get(obj) : "";
				 	 
				 	if (!String.class.equals(model.get(name).getClass())
		                    &&
!Number.class.isAssignableFrom(model.get(name).getClass()))
		                {
		                    Translator translator =
translatorSource.findByType(model.get(name).getPropertyType());
		                    if (translator != null)
		                    {
		                        val = translator.toClient(val);
		                    }
		                    else
		                    {
		                        val = val != null ? val.toString() : "";
		                    }
		                }
		    		 }
	             cell.append(name, val);
	    	 }	 
	    	 	    	 
	    	 rows.put(cell);
	     }
	    
		response.put("aaData", rows);
		
		return response;
	}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/datatable-ajax-with-new-column-tp5719395p5719409.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: datatable ajax with new column

Posted by rosecorp <ro...@gmail.com>.
Hi Manu,

You were partially right I think :). It's true you don't have to override
data model, but if you try to ad custom column like you are doing in your
example for instance any action button than it fails in default data model
throwing null pointer exception. Any suggestions? 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/datatable-ajax-with-new-column-tp5719395p5719406.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: datatable ajax with new column

Posted by Emmanuel DEMEY <de...@gmail.com>.
Normally, with the current SNAPSHOT, you do not have to override the
DataTableModel model. But I am not sure. can you test it ? if it does not
work, I will provide a new sample.
Manu


2013/1/20 rosecorp <ro...@gmail.com>

> Hello All,
>
> I am using datatables component in similar way which was presented here:
>
> http://tapestry5-jquery.com/other/datatableajaxwithnewcolumn but I am
> getting sam exception. I have updated datatables to the newest version but
> it didn't help. Do you know what is causing this problem?
>
> Many thanks for any answer.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/datatable-ajax-with-new-column-tp5719395.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Emmanuel DEMEY
Ingénieur Etude et Développement
ATOS Worldline
+33 (0)6 47 47 42 02
demey.emmanuel@gmail.com
http://emmanueldemey.fr/

Twitter : @EmmanuelDemey