dataTables not populating in struts2 hibernate - datatables

I have a jquery datable that should get loaded with a table data. I am using struts2 Hibernate.
JSP Page:
<script>
$(document).ready(function() {
$(".jqueryDataTable").dataTable({
"sPaginationType" : "full_numbers",
"bProcessing" : false,
"bServerSide" : false,
"sAjaxSource" : "getProductPropData",
"bJQueryUI" : true,
"aoColumns" : [
{ "mData": "densityId" },
{ "mData": "densityDescription" }
]
} );
} );
</script>
struts.xml
<package name="json" namespace="/" extends="json-default">
<action name="getProductPropData" class="com.test.action.PropertyListDataAction">
<result type="json">
<param name="excludeNullProperties">true</param>
<param name="noCache">true</param>
</result>
</action>
</package>
Action Class:
public String execute() throws Exception {
// TODO Auto-generated method stub
SessionFactory sf = (SessionFactory) ctx.getAttribute("SessionFactory");
ProductPropertyDAO pdao = new ProductPropertyDAOImpl(sf);
List<DensityGroup> dg = pdao.getProductPropListData("Density");
Gson gson = new Gson();
jsonData = gson.toJson(dg);
System.out.println("dg:"+dg);
return "success";
}
I am getting response from the database in json format but my datatable is not getting populated.
]2
JSON output:
{"jsonData":"[{\"densityId\":15,\"validationAware\":{}},{\"densityId\":11,\"densityDescription\":\"Mcvr\",\"validationAware\":{}},{\"densityId\":14,\"densityDescription\":\"test\",\"validationAware\":{}},{\"densityId\":16,\"densityDescription\":\"Chitti\",\"validationAware\":{}},{\"densityId\":12,\"densityDescription\":\"MCVR\",\"validationAware\":{}},{\"densityId\":13,\"densityDescription\":\"4\\\" DIA\",\"validationAware\":{}},{\"densityId\":14,\"densityDescription\":\"test\",\"validationAware\":{}},{\"densityId\":15,\"validationAware\":{}},{\"densityId\":21,\"densityDescription\":\"1 1\/4\\\" DIA\",\"validationAware\":{}},{\"densityId\":22,\"densityDescription\":\"3\/4\\\" DIA\",\"validationAware\":{}},{\"densityId\":37,\"densityDescription\":\"25\\\"DIA\",\"validationAware\":{}},{\"densityId\":24,\"densityDescription\":\"8\\\" DIA\",\"validationAware\":{}},{\"densityId\":25,\"densityDescription\":\"1 1\/8\\\" DIA\",\"validationAware\":{}},{\"densityId\":28,\"densityDescription\":\"6\\\"\",\"validationAware\":{}},{\"densityId\":29,\"densityDescription\":\"1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":30,\"densityDescription\":\"EXHAUST STEAM\",\"validationAware\":{}},{\"densityId\":19,\"densityDescription\":\"1 1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":44,\"densityDescription\":\"EXHAUSTCLADDING\",\"validationAware\":{}},{\"densityId\":1,\"densityDescription\":\"16 KG\",\"validationAware\":{}},{\"densityId\":11,\"densityDescription\":\"Mcvr\",\"validationAware\":{}},{\"densityId\":2,\"densityDescription\":\"20 KG\",\"validationAware\":{}},{\"densityId\":3,\"densityDescription\":\"24 KG\",\"validationAware\":{}},{\"densityId\":5,\"densityDescription\":\"48 KG\",\"validationAware\":{}},{\"densityId\":6,\"densityDescription\":\"64 KG\",\"validationAware\":{}},{\"densityId\":7,\"densityDescription\":\"96 KG\",\"validationAware\":{}},{\"densityId\":8,\"densityDescription\":\"100 KG\",\"validationAware\":{}},{\"densityId\":9,\"densityDescription\":\"128 KG \",\"validationAware\":{}},{\"densityId\":10,\"densityDescription\":\"120 KG \",\"validationAware\":{}},{\"densityId\":18,\"densityDescription\":\"144KG\",\"validationAware\":{}},{\"densityId\":23,\"densityDescription\":\"5\\\" DIA\",\"validationAware\":{}},{\"densityId\":26,\"densityDescription\":\"4\\\"\",\"validationAware\":{}},{\"densityId\":27,\"densityDescription\":\"125 KG\",\"validationAware\":{}},{\"densityId\":34,\"densityDescription\":\"10\\\" DIA\",\"validationAware\":{}},{\"densityId\":32,\"densityDescription\":\"18\\\" \",\"validationAware\":{}},{\"densityId\":33,\"densityDescription\":\"12\\\" DIA\",\"validationAware\":{}},{\"densityId\":35,\"densityDescription\":\"14\\\" DIA\",\"validationAware\":{}},{\"densityId\":36,\"densityDescription\":\"5\/8\\\" DIA\",\"validationAware\":{}},{\"densityId\":38,\"densityDescription\":\"(1\/2 x 24 SWG)\",\"validationAware\":{}},{\"densityId\":39,\"densityDescription\":\"8\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":40,\"densityDescription\":\"6\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":41,\"densityDescription\":\"3\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":42,\"densityDescription\":\"25 MM DIA\",\"validationAware\":{}},{\"densityId\":43,\"densityDescription\":\"150 KG\",\"validationAware\":{}},{\"densityId\":46,\"densityDescription\":\"INSULATION WORK\",\"validationAware\":{}},{\"densityId\":47,\"densityDescription\":\"18\\\" DIA\",\"validationAware\":{}},{\"densityId\":16,\"densityDescription\":\"Chitti\",\"validationAware\":{}},{\"densityId\":45,\"densityDescription\":\"1 3\/8 DIA\",\"validationAware\":{}},{\"densityId\":56,\"densityDescription\":\"18 KG\",\"validationAware\":{}},{\"densityId\":55,\"densityDescription\":\"40 KG\",\"validationAware\":{}},{\"densityId\":48,\"densityDescription\":\"85 KG\",\"validationAware\":{}},{\"densityId\":49,\"densityDescription\":\"2\\\"\",\"validationAware\":{}},{\"densityId\":50,\"densityDescription\":\"12 KG\",\"validationAware\":{}},{\"densityId\":53,\"densityDescription\":\"FLANGES\",\"validationAware\":{}},{\"densityId\":51,\"densityDescription\":\"2 1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":52,\"densityDescription\":\"INSULATION \",\"validationAware\":{}},{\"densityId\":54,\"densityDescription\":\"VALVES\",\"validationAware\":{}},{\"densityId\":57,\"densityDescription\":\"CLASS O\",\"validationAware\":{}},{\"densityId\":58,\"densityDescription\":\"140 KG\",\"validationAware\":{}},{\"densityId\":59,\"densityDescription\":\"30 KG\",\"validationAware\":{}}]"}

By default datatables looks for the 'data' element in the json.
It can't find it, therefore it's 'undefined'. DataTables provides a way to specify the element to use. Comparing your json with that on the documentation link below you should be able to specify ajax.dataSrc = "jsonData" or change "jsonData" to "data" in your data object.
I would recommend switching to the new naming convention for the datatable options if possible, it's more clear and the documentation is tailored towards it. If you can't use the new naming scheme changing your json object is probably the best option.
Documentation:
https://datatables.net/examples/ajax/custom_data_property.html

Related

How to hundle update many or some value of SQL Statement from WSO2 DataService?

I have a SQL Statement like this :
UPDATE students
SET name = :name, school = :school, grade = :grade
WHERE id = :id AND school = :school
I would like to expose this SQL as an API update using the WSO2 Dataservice.
It worked for me but i have to set all the value in the JSON payload like this :
{
"_putupdateprofile": {
"name":"oussama",
"school": "AL-ZOUHOUR",
"grade": "A1",
"id": 123
}
}
where my objectif is to be able to update only one value like this :
{
"_putupdateprofile": {
"name":"oussama",
"id": 123
}
}
So does WSO2 DataService support this?
I tried this and it worked for me but i still have problem to put where parameters optional
<param name="school" paramType="SCALAR" sqlType="STRING" optional="true" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" optional="true" />
Seems your requirement is to make some parameters optional. To make parameters optional you can add a default value as shown below.
<param name="school" paramType="SCALAR" sqlType="STRING" defaultValue="#{NULL}" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" defaultValue="#{NULL}" />
Note: You may have to change the default value based on the DB type.
Having said the above, If you don't want to update your record with the default values you may have to update your query to omit the fields you don't want to update in your query.

How to bring a multi-datatable with pagination,sorting,filtering in single component file in angular 7

I am trying to get multi-table with pagination, sorting, filtering in a single component.
I can get pagination for one table, unable to get pagination for multiple tables in a single component.
I also received the data from all tables. I am receiving the data from the backend so it takes a few seconds.
I Couldn't find any multi-data table example in angular7 material
This is my code
displayedColumns: string[] = ['name', 'id', 'products_count', 'domain'];
public dataSource = new MatTableDataSource<PeriodicElement>(this.ELEMENT_DATA);
public NONAR_ELEMENT_DATA: NonARElement[];
displayedColumns1: string[] = ['pro_id', 'name', 'd_image'];
public dataSource1 = new MatTableDataSource<NonARElement>(this.NONAR_ELEMENT_DATA);
#ViewChild('paginator') paginator: MatPaginator;
#ViewChild('paginator1', { read: MatPaginator }) paginator1: MatPaginator;
_setDataSource(indexNumber) {
console.log("indexNumber", indexNumber)
setTimeout(() => {
switch (indexNumber) {
case 0:
!this.dataSource1.paginator ? this.dataSource1.paginator = this.paginator1 : null;
console.log("this.dataSource-NON AR.paginator", this.dataSource.paginator)
break;
case 1:
!this.dataSource.paginator ? this.dataSource.paginator = this.paginator : null;
console.log("this.dataSource-Storelist.paginator", this.dataSource1.paginator)
}
},1000);
}```
Can you share your html page. Have you used this #name in your paginator?
<mat-paginator #paginator length="100"
pageSize="20"
pageSizeOptions="[10,20,30]"
(page)="pageChanged($event)">
</mat-paginator>
#ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;

Dropzone.js - creating dropzones programmatically returns "dropzone is not a function"

I'm trying to create dropzones programmatically through a function but I receive a element.dropzone is not a function error and I'm not quite sure why. I'm using Vue.js with Element UI
HTML
<div class="toUpload">
<div class="el-upload el-upload--text">
JS
submitMessage (){
return api.createMessage( messageToSend, ( message ) => {
// some code
this.insertAttachments( "toUpload", message.id );
} )
},
insertAttachments ( element, messageId ) {
element.dropzone( {
url: '/messages/' + messageId + '/attachments',
paramName: 'attachment',
previewsContainer: false,
uploadedMultiple: true,
maxfiles: 10,
parallelUploads: 10
} )
The value of element is a String ("toUpload") at the point where you are calling element.dropzone(). To use the dropzone method like that, you need to call it on a jQuery element.
You probably meant something like this:
$('.' + element).dropzone( ...

Sorting on date field with Sitecore 7 ContentSearch

I'm trying to add a field sort to a date field in a ContentSearch query. I'm able to filter on the index field properly so I'm assuming the field is getting populated with values properly, however, results are not being sorted properly. Any thoughts? Here's the code I'm using to do query:
public static IEnumerable<Episode> GetPastEpisodes(Show show, bool includeMostRecent = false, int count = 0)
{
IEnumerable<Episode> pastEpisodes;
using (var context = _index.CreateSearchContext())
{
// querying against lucene index
pastEpisodes = context.GetQueryable<Episode>().Where(GetPastAirDatePredicate(show));
if(!includeMostRecent)
{
pastEpisodes = pastEpisodes.Where(item => item.Id != GetMostRecentEpisode(show).Id);
}
pastEpisodes = pastEpisodes.OrderByDescending(ep => ep.Latest_Air_Date);
if (count > 0)
{
pastEpisodes = pastEpisodes.Take(count);
}
pastEpisodes = pastEpisodes.ToList();
// map the lucene documents to Sitecore items using the database
foreach (var episode in pastEpisodes)
{
_database.Map(episode);
}
}
return pastEpisodes;
}
private static Expression<Func<Episode,bool>> GetPastAirDatePredicate(Show show)
{
var templatePredicate = PredicateBuilder.Create<Episode>(item => item.TemplateId == IEpisodeConstants.TemplateId);
var showPathPredicate = PredicateBuilder.Create<Episode>(item => item.FullPath.StartsWith(show.FullPath));
var airDatePredicate = PredicateBuilder.Create<Episode>(item => item.Latest_Air_Date < DateTime.Now.Date.AddDays(1));
var fullPredicate = PredicateBuilder.Create<Episode>(templatePredicate).And(showPathPredicate).And(airDatePredicate);
return fullPredicate;
}
The field is stored and untokenized and using the LowerCaseKeywordAnalyzer.
<field fieldName="latest_air_date" storageType="YES" indexType="UN_TOKENIZED" vectorType="NO" boost="1f" type="System.DateTime" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider"/>
</field>
Episode class has IndexField attribute set:
[IndexField("latest_air_date")]
public virtual DateTime Latest_Air_Date {get; set; }
Kyle,
As far as I can tell everything looks correct with your configuration and code. I mocked out something very similar in a vanilla Sitecore 7.2 instance and Dates sorted without issue.
One thing to note though, and this might be what is giving you some issues, is that Sitecore's FieldReader for DateTime only store the date portion of the DateTime. If you are expecting to be able to sort by true DateTime you will need to add a custom FieldReader or some computed fields.
See this blog that discusses the issue and explains the process to swap out a custom field reader: http://reasoncodeexample.com/2014/01/30/indexing-datetime-fields-sitecore-7-content-search/
I would also suggest looking at the index with Luke to verify what data is actually in the index. https://code.google.com/p/luke/
And finally you may want to enable Search debugging in Sitecore to see exactly how Sitecore is executing the query in Lucene.
Sitecore.ContentSearch.config:
<setting name="ContentSearch.EnableSearchDebug" value="true" />

Can you create a Restriction for a Detached Criteria on a primitive collection?

I would like to know if there is a way to create a Restriction on a primitive collection of a Model in NHibernate.3.3.3?
Here's the details:
class Parent {
IEnumerable<string> ChildNames { get; set; }
}
I need to search like so:
private DetachedCriteria BuildQuery() {
var inNames = { "Bob", "Sam", "Dan" };
var query = DetachedCriteria.For<Parent>("parent");
query.Add(Restrictions.In("ChildNames", inNames));
return query;
}
I found this old question that says it's not possible, but given the fact that it's old and doesn't have a ton of upvotes, I'd like to confirm before I refactor.
If I can do it and I'm totally botching it, I'll take that help as well!
In this scenario, we can use Projection (something less type-safe, then mapped Property, but more flexible).
Let's expect the mapping like this:
<bag name="ChildNames" inverse="false" lazy="true" table="[dbo].[ChildNames]"
cascade="all"
batch-size="25">
<key column="ParentId" />
<element type="System.String" column="ChildName" />
</bag>
Then we can adjust the Build query method like this:
protected virtual DetachedCriteria BuildQuery()
{
var inNames = new [] { "Bob", "Sam", "Dan" };
// parent query reference
var query = DetachedCriteria.For<Parent>("parent");
// reference to child query
var child = query.CreateCriteria("ChildNames");
// let's project the column name of the Element, e.g. 'Name'
var columnNameProjection = Projections.SqlProjection(
"ChildName as name", null, new IType[] { NHibernateUtil.String }
);
// in clause
child.Add(Restrictions.In(
columnNameProjection, inNames
));
return query;
}
And this is what we will get:
SELECT ...
FROM Parent this_
inner join [dbo].[ChildNames] childNames3_
on this_.ParentId=childNames3_.ParentId
WHERE ChildName in (#p0, #p1, #p2)
...
#p0=N'Bob',#p1=N'Sam',#p2=N'Dan'
The caveat:
While this is in deed working... the ChildName is used without the Alias. That could be pretty tricky to fulfill... so be careful, if there are more columns with the name ChildName in this scenario
I ended up, like many, refactoring the collection into a strong type.