i'm having a problem with jqgrid searching. my code works perfectly with add, edit, delete except searching. Once I load it the data shown fine, but if I click find button, it never does anything.
I have been looking for it everywhere but I can't find what's wrong. If I use loadonce : true then searching works but now having problem with paging and sorting the grid. I wanna make it work perfectly with paging, sorting, and searching.
here's my code.
$("#material_list").jqGrid({
url:"MY URL",
editurl:"MY URL",
mtype:"post",
caption:"LIST",
datatype:"json",
height:"auto",
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true
},
rowNum:10,
rowList:[5,10,15],
colNames:["PROD_CODE","PROD_NAME","COMP_CODE","UNIT","STANDARD","USEFLAG"],
colModel:[
{name:"PROD_CODE", index:"PROD_CODE", editable:true},
{name:"PROD_NAME", index:"PROD_NAME", editable:true},
{name:"COMP_CODE", index:"COMP_CODE", editable:true},
{name:"UNIT", index:"UNIT", editable:true},
{name:"STANDARD", index:"STANDARD", editable:true},
{name:"USEFLAG", index:"USEFLAG", editable:true}
],
pager:"#pager",
autowidth:true,
viewrecords:true,
//loadonce:true,
});
$("#material_list").jqGrid(
"navGrid",
"#pager",
{search:true, edit:true, add:true, del:true},
{closeAfterEdit:true, reloadAfterSubmit:true},
{closeAfterAdd:true, reloadAfterSubmit:true},
{reloadAfterSubmit:true}
);
Related
We using elastic 7.13
we are doing periodical update to index using upsert
The sequence of operations
create new index with dynamic mapping all strings mapped as text
"dynamic_templates": [
{
"strings_as_keywords": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "search_term_analyzer",
"copy_to": "_all",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
}
}
}
]
upsert bulk with the attached code (I don't have equivalent with rest)
doing search on specific filed
localhost:9200/mdsearch-vitaly123/_search
{
"query": {
"match": {
"fullyQualifiedName": `value_test`
}
}
}
got 1 result
upsert again now "fullyQualifiedName": "value_test1234" (as in step 2)
do search as in step 3
got 2 results 1 doc with "fullyQualifiedName": "value_test"
and other "fullyQualifiedName": "value_test1234"
snippet below of upsert (step 2):
#Override
public List<BulkItemStatus> updateDocumentBulk(String indexName, List<JsonObject> indexDocuments) throws MDSearchIndexerException {
BulkRequest request = new BulkRequest().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
ofNullable(indexDocuments).orElseThrow(NullPointerException::new)
.forEach(x -> {
var id = x.get("_id").getAsString();
x.remove("_id");
request.add(new UpdateRequest(indexName, id)
.docAsUpsert(true)
.doc(x.toString(), XContentType.JSON)
.retryOnConflict(3)
);
});
BulkResponse bulk = elasticsearchRestClient.bulk(request, RequestOptions.DEFAULT);
return stream(bulk.getItems())
.map(r -> new BulkItemStatus(r.getId(), isSuccess(r), r.getFailureMessage()))
.collect(Collectors.toList());
}
I can search by updated properties.
But the problem is that searches retrieve "updated fields" and previous one as well.
How can I solve it ?
maybe limit somehow the version number to be only 1.
I set setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) but it didn't helped
Here in picture we can see result
P.S - old and updated data retrieved as well
Suggestions ?
Regards,
What is happening is that the following line must yield null:
var id = x.get("_id").getAsString();
In other words, there is no _id field in the JSON documents you pass in indexDocuments. It is not allowed to have fields with an initial underscore character in the source documents. If it was the case, you'd get the following error:
Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.
Hence, your update request cannot update any document (since there's no ID to identify the document to update) and will simply insert a new one (i.e. what docAsUpsert does), which is why you're seeing two different documents.
I am using Sublime Text 3 and I can't (that means when I press the key nothing happens) . while I have active java syntax. When I switch to another syntax (f.e. Javascript) problem is gone. Do anyone solved had/solved this problem?
[Installed packages]
{
"installed_packages":
[
"AngularJS",
"Better JavaScript",
"Display Functions (Java)",
"DocBlockr",
"EditorConfig",
"Emmet",
"Format SQL",
"Git",
"Goto Documentation",
"Grunt",
"HexViewer",
"HTML Boilerplate",
"HTML5",
"JavaPropertiesEditor",
"Javascript Beautify",
"jQuery",
"JsFormat",
"LESS",
"LineEndings",
"MoveTab",
"Nette",
"Nunjucks Syntax",
"Package Control",
"PHP Namespace Command",
"PHP-Twig",
"Phpcs",
"PhpDoc",
"Quick File Move",
"SideBarEnhancements",
"SJSON",
"SublimeLinter",
"SublimeLinter-csslint",
"SublimeLinter-html-tidy",
"SublimeLinter-jshint",
"SublimeLinter-json",
"SublimeLinter-php",
"Theme - Phoenix",
"VCS Gutter",
"WordCount"
]
}
[User settings]
{
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"default_line_endings": "unix",
"detect_slow_plugins": false,
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": true,
"font_face": "Consolas",
"font_size": 10,
"highlight_line": true,
"ignored_packages":
[
"JavaScript",
"Vintage",
"tern_for_sublime"
],
"show_encoding": true,
"show_line_endings": true,
"translate_tabs_to_spaces": true
}
According to sergioFC comment I did sublime.log_commands(True) and it showed up that package Display Functions (Java) is "blocking" the . key. Disabling the package solved my problem.
I have a jqGrid with code similar to following sample code:
jQuery("#list10").jqGrid({
url:'MyServlateName?action=MyAction',
datatype: "xml",
mtype:"POST",
ajaxSelectOptions: {type: "POST"},
sortable: true,
height: "100%",
rowNum:4,
width: 1000,
emptyrecords: "No Records to display",
colNames:['Contact No', 'Cust ID', 'Name'],
colModel:[
{name:'CNO',index:'CNO', width:80,sortable:true},
{name:'CUSTID',index:'CUSTID', width:60,sortable:true},
{name:'CNAME',index:'CNAME', width:200,sortable:true, searchoptions:{ sopt:['cn']}},
],
pager: '#pager10',
viewrecords: true,
sortname: 'CUSTID',
shrinkToFit: false,
toppager: true,
sortorder: "asc"
}
}).navGrid('#pager10',{cloneToTop:true, edit:false,add:false,del:false,view:true,search: false, refresh:true},
{},
{},
{},
{},
{recreateForm: true,width:700,navkeys: [true,38,40]}
);
jQuery("#list10").jqGrid('bindKeys');
$("#list10").jqGrid('filterToolbar', {stringResult: true,searchOnEnter: false});
In filterToolbar I am putting CUSTID programmatically using following code:
document.getElementById("gs_CUSTID").value=CUST_ID_VAR_NAME;
It is showing the value in filterToolbar in CUSTID column but grid is not populated/searched according to the CUSTID I have put(NO SEARCH HAPPENS). If I do regular search using filterToolbar then it works fine.
Any suggestion will be appreciated.
You can fix the problem in different ways. For example you can trigger change event on #gs_CUSTID after setting the value in the control:
$("#gs_CUSTID").val("123");
$("#gs_CUSTID").trigger("change");
More better will be to set datatype: "local" initially in the grid. It will prevent loading of unfiltered data from 'MyServlateName?action=MyAction' during creating the grid. After that you can change datatype to "xml" using setGridParam, set value in #gs_CUSTID and trigger the change event at the end.
$("#list10").jqGrid("setGridParam", {datatype: "xml"});
$("#gs_CUSTID").val("123");
$("#gs_CUSTID").trigger("change");
Instead of triggering change you can call triggerToolbar method manually (see the part of jqGrid code):
$("#list10").jqGrid("setGridParam", {datatype: "xml"});
$("#gs_CUSTID").val("123");
$("#list10")[0].triggerToolbar();
I want to know how to iterate a JSON object using jQuery. My requirement is I am getting a list from a Java Servlet to the UI and I have to populate a combo box with the AJAX response.
The above tack I already did it using struts2 and jQuery. Now I am in the middle of nowhere, how to iterate the Java List back in JSP:
$("#XXX option").remove();
$.each(data.YYYList, function(index, item) {
$("#XXX").append($("<option></option>").text(item).val(item));
});
I have set the MIME type as response.setContentType("application/json");
Can any one please guide me how to achieve this. Please let me know if any other information is needed from me.
Based on the small amount of information given by Esh, here is an example that I created for the very function you listed. I have a JSON that I want to be used in multiple select boxes.
Fiddle
Example Json:
"yyyList": [
{
"Id": "1",
"Name": "aaaa "
}, {
"Id": "2",
"Name": "bbb "
}, {
"Id": "6",
"Name": "ccc "
}, {
"Id": "7",
"Name": "ddd "
} ]
$.ajax({
url: "URL",
//data: "",
type: "GET",
dataType: 'json',
success: function (data) {
$.each(data.YYYList, function () {
$('#state').append('<'option value='+this.Id+'>'+this.Name+'<'option>');
});
}
})
$('#state') ---> gives the same id for select tag in HTML
Please make correct it option syntax
Hope this helps.
I am trying to return two json sets from java which each contain key/value pairs. I can get the data to return as expected but once I have the data I can not access it properly. Here is what my data coming from the java looks like
{"RESULTS":
{"MAP_1":
[
{"value":"1","display":"output text","type":"type a"},
{"value":"2","display":"more output text","type":"type a"}
],
"MAP_2":
[
{"value":"1","display":"output text","type":"type b"},
{"value":"2","display":"more output text","type":"type b"}
]
}
}
I have tried using $.map and $.each but I can not seem to drill into the data any help would be greatly appeciated.
Here is my latest attempt:
$.ajax({
url: url,
dataType: "text",
data: {
searchString: request.term
},
success: function( data ) {
response( $.map( data.MAP_1, function( item ) {
label: item.value + ", " + item.type
value: item.display
}));
}
});
Thanks in advance!
The format of the data returned by java is text, not json. So you should specify the dataType as json. In addition the following code are not right, I think.
data.MAP_1
should be
data.RESULTS.MAP_1