Xquery multiple repeating nodes - xquery

I need to build multiple instances of the Node InfoExpoRisco, each of this will be represented by a distinct-value of "Matricula" on my request.
Each InfoExpoRisco have 3 Nodes that could repeat:
InfoExpoRisco/AgNocs/AgNoc;
InfoExpoRisco/AgNocs/AgNoc/epis/epi;
InfoExpoRisco/responsaveisReg/respReg
declare variable $dbOutput as element()* external;
declare variable $request as element()*external;
declare function local:ObterS2240InfoExpRiscoResponse($dbOutput as element()* (:: schema-element(ns1:ObterS2240InfoExpRisco_dbOutputCollection)* ::),
$request as element()* (:: schema-element(ns2:ObterS2240InfoExpRiscoRequest)* ::))
as element()* (:: schema-element(ns2:ObterS2240InfoExpRiscoResponse)* ::) {
<ns2:ObterS2240InfoExpRiscoResponse>
{
for $matriculaRequest in distinct-values($request/ns2:Agente/ns2:Matricula/text())
for $ObterS2240InfoExpRisco_dbOutput in $dbOutput/ns1:ObterS2240InfoExpRisco_dbOutput
where $ObterS2240InfoExpRisco_dbOutput/ns1:MATRICULA/text() = $matriculaRequest
return
<ns2:InfoExpoRisco>
<ns2:sistemaOrigem>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:SISTEMA_ORIGEM)}</ns2:sistemaOrigem>
<ns2:cdSapEmpresa>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:CD_SAP_EMPRESA)}</ns2:cdSapEmpresa>
<ns2:matricula>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:MATRICULA)}</ns2:matricula>
<ns2:dataAtualizacao>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:DATA_ATUALIZACAO)}</ns2:dataAtualizacao>
<ns2:dtIniCondicao>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:DTINICONDICAO)}</ns2:dtIniCondicao>
<ns2:localAmb>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:LOCALAMB)}</ns2:localAmb>
<ns2:dscSetor>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:DSCSETOR)}</ns2:dscSetor>
<ns2:tpInsc>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:TPINSC)}</ns2:tpInsc>
<ns2:nrInsc>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:NRINSC)}</ns2:nrInsc>
<ns2:dscAtivDes>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:DSCATIVDES)}</ns2:dscAtivDes>
<ns2:obsCompl>{fn:data($ObterS2240InfoExpRisco_dbOutput/ns1:OBSCOMPL)}</ns2:obsCompl>
<ns2:agNocs>
{
for $agNoc in $dbOutput/ns1:ObterS2240InfoExpRisco_dbOutput
where $agNoc/ns1:MATRICULA/text() = $matriculaRequest
return
<ns2:agNoc>
{
if(fn:data($agNoc/ns1:CODAGNOC ne '')) then(
<ns2:codAgNoc>{fn:data($agNoc/ns1:CODAGNOC)}</ns2:codAgNoc>) else()
}
{
if(fn:data($agNoc/ns1:DSCAGNOC ne '')) then(
<ns2:dscAgNoc>{fn:data($agNoc/ns1:DSCAGNOC)}</ns2:dscAgNoc>) else()
}
{
if(fn:data($agNoc/ns1:TPAVAL ne '')) then(
<ns2:tpAval>{fn:data($agNoc/ns1:TPAVAL)}</ns2:tpAval>) else()
}
{
if(fn:data($agNoc/ns1:INTCONC ne '')) then(
<ns2:intConc>{fn:data($agNoc/ns1:INTCONC)}</ns2:intConc>) else()
}
{
if(fn:data($agNoc/ns1:LIMTOL ne '')) then(
<ns2:limTol>{fn:data($agNoc/ns1:LIMTOL)}</ns2:limTol>) else()
}
{
if(fn:data($agNoc/ns1:UNMED ne '')) then(
<ns2:unMed>{fn:data($agNoc/ns1:UNMED)}</ns2:unMed>) else()
}
{
if(fn:data($agNoc/ns1:TECMEDICAO ne '')) then(
<ns2:tecMedicao>{fn:data($agNoc/ns1:TECMEDICAO)}</ns2:tecMedicao>) else()
}
<ns2:epcEpi>
<ns2:utilizEPC>{fn:data($agNoc/ns1:UTILIZEPC)}</ns2:utilizEPC>
<ns2:eficEpc>{fn:data($agNoc/ns1:EFICEPC)}</ns2:eficEpc>
<ns2:utilizEPI>{fn:data($agNoc/ns1:UTILIZEPI)}</ns2:utilizEPI>
<ns2:eficEpi>{fn:data($agNoc/ns1:agno_EFICEPI)}</ns2:eficEpi>
</ns2:epcEpi>
<ns2:epis>
{
for $epi in $dbOutput/ns1:ObterS2240InfoExpRisco_dbOutput
where $epi/ns1:MATRICULA/text() = $matriculaRequest
return
<ns2:epi>
{
if(fn:data($epi/ns1:DOCAVAL ne '')) then(
<ns2:docAval>{fn:data($epi/ns1:DOCAVAL)}</ns2:docAval>) else()
}
{
if(fn:data($epi/ns1:DSCEPI ne '')) then(
<ns2:dscEPI>{fn:data($epi/ns1:DSCEPI)}</ns2:dscEPI>) else()
}
{
if(fn:data($epi/ns1:MEDPROTECAO ne '')) then(
<ns2:medProtecao>{fn:data($epi/ns1:MEDPROTECAO)}</ns2:medProtecao>) else()
}
{
if(fn:data($epi/ns1:CONDFUNCTO ne '')) then(
<ns2:condFuncto>{fn:data($epi/ns1:CONDFUNCTO)}</ns2:condFuncto>) else()
}
{
if(fn:data($epi/ns1:USOININT ne '')) then(
<ns2:usoInint>{fn:data($epi/ns1:USOININT)}</ns2:usoInint>) else()
}
{
if(fn:data($epi/ns1:PRZVALID ne '')) then(
<ns2:przValid>{fn:data($epi/ns1:PRZVALID)}</ns2:przValid>) else()
}
{
if(fn:data($epi/ns1:PERIODICTROCA ne '')) then(
<ns2:periodicTroca>{fn:data($epi/ns1:PERIODICTROCA)}</ns2:periodicTroca>) else()
}
{
if(fn:data($epi/ns1:HIGIENIZACAO ne '')) then(
<ns2:higienizacao>{fn:data($epi/ns1:HIGIENIZACAO)}</ns2:higienizacao>) else()
}
</ns2:epi>
}
</ns2:epis>
</ns2:agNoc>
}
</ns2:agNocs>
<ns2:responsaveisReg>
{
for $respReg in $dbOutput/ns1:ObterS2240InfoExpRisco_dbOutput
where $respReg/ns1:MATRICULA/text() = $matriculaRequest
return
<ns2:respReg>
{
if(fn:data($respReg/ns1:CPFRESP ne '')) then(
<ns2:cpfResp>{fn:data($respReg/ns1:CPFRESP)}</ns2:cpfResp>) else()
}
{
if(fn:data($respReg/ns1:IDEOC ne '')) then(
<ns2:ideOC>{fn:data($respReg/ns1:IDEOC)}</ns2:ideOC>) else()
}
{
if(fn:data($respReg/ns1:DSCOC ne '')) then(
<ns2:dscOC>{fn:data($respReg/ns1:DSCOC)}</ns2:dscOC>) else()
}
{
if(fn:data($respReg/ns1:NROC ne '')) then(
<ns2:nrOC>{fn:data($respReg/ns1:NROC)}</ns2:nrOC>) else()
}
{
if(fn:data($respReg/ns1:UFOC ne '')) then(
<ns2:ufOC>{fn:data($respReg/ns1:UFOC)}</ns2:ufOC>) else()
}
{
if(fn:data($respReg/ns1:MATR_CPF_FUA0017_010 ne '')) then(
<ns2:MATR_CPF_FUA0017_010>{fn:data($respReg/ns1:MATR_CPF_FUA0017_010)}</ns2:MATR_CPF_FUA0017_010>) else()
}
{
if(fn:data($respReg/ns1:RESP_TEC_ALA0001_440 ne '')) then(
<ns2:RESP_TEC_ALA0001_440>{fn:data($respReg/ns1:RESP_TEC_ALA0001_440)}</ns2:RESP_TEC_ALA0001_440>) else()
}
</ns2:respReg>
}
</ns2:responsaveisReg>
</ns2:InfoExpoRisco>
}
</ns2:ObterS2240InfoExpRiscoResponse>
What is missing to filter the repeating nodes for this example of $dbOutput
<ObterS2240InfoExpRisco_dbOutputCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/ObterS2240InfoExpRisco"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<ObterS2240InfoExpRisco_dbOutput>
<SISTEMA_ORIGEM>2</SISTEMA_ORIGEM>
<CD_SAP_EMPRESA>1000</CD_SAP_EMPRESA>
<MATRICULA>5413803</MATRICULA>
<DATA_ATUALIZACAO>2021-09-01 17:01:17</DATA_ATUALIZACAO>
<DTINICONDICAO>2021-02-01 00:00:00</DTINICONDICAO>
<LOCALAMB>1</LOCALAMB>
<DSCSETOR>RECAP REF DE CAPUAVA</DSCSETOR>
<TPINSC>1</TPINSC>
<NRINSC>33000167085263</NRINSC>
<DSCATIVDES>Analises de amostras, Atividade Administrativa, Drenagem de sistema, Manuseio de Equipamento</DSCATIVDES>
<OBSCOMPL/>
<MATR_CPF_FUA0017_010/>
<RESP_TEC_ALA0001_440/>
<CPFRESP>23807862080</CPFRESP>
<IDEOC>4</IDEOC>
<DSCOC/>
<NROC>1234</NROC>
<UFOC>GO</UFOC>
<CODAGNOC>02.01.001</CODAGNOC>
<DSCAGNOC>Ruído contínuo ou intermitente (Q5)</DSCAGNOC>
<TPAVAL>1</TPAVAL>
<INTCONC>83</INTCONC>
<LIMTOL/>
<UNMED>4</UNMED>
<TECMEDICAO>NR 15 - ANEXO 1 (q=5)</TECMEDICAO>
<UTILIZEPC>2</UTILIZEPC>
<EFICEPC>S</EFICEPC>
<UTILIZEPI>1</UTILIZEPI>
<agno_EFICEPI/>
<DOCAVAL/>
<DSCEPI/>
<MEDPROTECAO/>
<CONDFUNCTO/>
<USOININT/>
<PRZVALID/>
<PERIODICTROCA/>
<HIGIENIZACAO/>
</ObterS2240InfoExpRisco_dbOutput>
<ObterS2240InfoExpRisco_dbOutput>
<SISTEMA_ORIGEM>2</SISTEMA_ORIGEM>
<CD_SAP_EMPRESA>1000</CD_SAP_EMPRESA>
<MATRICULA>5413803</MATRICULA>
<DATA_ATUALIZACAO>2021-09-01 17:01:17</DATA_ATUALIZACAO>
<DTINICONDICAO>2021-02-01 00:00:00</DTINICONDICAO>
<LOCALAMB>1</LOCALAMB>
<DSCSETOR>RECAP REF DE CAPUAVA</DSCSETOR>
<TPINSC>1</TPINSC>
<NRINSC>33000167085263</NRINSC>
<DSCATIVDES>Analises de amostras, Atividade Administrativa, Drenagem de sistema, Manuseio de Equipamento</DSCATIVDES>
<OBSCOMPL/>
<MATR_CPF_FUA0017_010/>
<RESP_TEC_ALA0001_440/>
<CPFRESP>05611780709</CPFRESP>
<IDEOC>9</IDEOC>
<DSCOC>CRQ</DSCOC>
<NROC>857496</NROC>
<UFOC>RJ</UFOC>
<CODAGNOC>02.01.001</CODAGNOC>
<DSCAGNOC>Ruído contínuo ou intermitente (Q5)</DSCAGNOC>
<TPAVAL>1</TPAVAL>
<INTCONC>83</INTCONC>
<LIMTOL/>
<UNMED>4</UNMED>
<TECMEDICAO>NR 15 - ANEXO 1 (q=5)</TECMEDICAO>
<UTILIZEPC>2</UTILIZEPC>
<EFICEPC>S</EFICEPC>
<UTILIZEPI>1</UTILIZEPI>
<agno_EFICEPI/>
<DOCAVAL/>
<DSCEPI/>
<MEDPROTECAO/>
<CONDFUNCTO/>
<USOININT/>
<PRZVALID/>
<PERIODICTROCA/>
<HIGIENIZACAO/>
</ObterS2240InfoExpRisco_dbOutput>
</ObterS2240InfoExpRisco_dbOutputCollection>
This example should be 1 InfoExpoRisco with 1 AgNoc/0 Epi and 2 RespReg.
I've got worse examples with 4 AgNocs, each with 4 Epis but the maximum digits restriction dont let me paste here

Solved using functx:distinct-deep and specific functions to list all repeating nodes. Then a main function calling all functions as distinct-deep.

Related

How to fetch #value from following json

I have following json.I want to fetch "rdfs:label"'s value when "#type" is "T:Class".
I want output like
Stand1
Stand2
How to achieved this.
I have tried like this.
string json = File.ReadAllText("Filepath");
JObject Search = JObject.Parse(json);
IList results = Search["#standard"][0].Children().ToList();
foreach (JToken result in results)
{
}
It gives me entire inner #standard block.
{
"#School": {
"name": "Vikas Mandir",
"subject": "Maths",
"author": "Joshi",
},
"#standard": [
{
"#id": "vikas:Stand1",
"#standard": [
{
"#id": "vikas:Stand12",
"#type": "T:Class",
"tag:Std:label": {
"#value": "Stand1"
},
"rdfs:label": {
"#value": "Stand1"
}
},
{
"#id": "vikas:Stand123",
"#type": "T:Class",
"tag:Std:label": {
"#value": "Stand2"
},
"rdfs:label": {
"#value": "Stand2"
}
}
]
}
]
}
try this
var prop = new List<JToken>();
GetObject(jsonParsed, prop, "rdfs:label", null, true);
List<string> found = prop.Where(i => (string)i["#type"] == "T:Class")
.Select(i => (string) ((JObject)i).Properties().First(x => x.Name == "rdfs:label").Value["#value"]).ToList();
Console.WriteLine(string.Join(",",found)); //Stand1,Stand2
helper
public void GetObject(JToken obj, List<JToken> result, string name = null, string value = null, bool getParent = false)
{
if (obj.GetType().Name == "JObject")
foreach (var property in ((JObject)obj).Properties())
{
if (property.Value.GetType().Name == "JValue"
&& (name == null || (string)property.Name == name)
&& (value == null || (string)property.Value == value))
{
if (getParent) result.Add(property.Parent); else result.Add(property);
}
else if (property.Value.GetType().Name == "JObject")
{
if (name != null && (string)property.Name == name) result.Add(property.Parent);
GetObject(property.Value, result, name, value);
}
else if (property.Value.GetType().Name == "JArray") GetObject(property.Value, result, name, value);
}
if (obj.GetType().Name == "JArray")
{
foreach (var property in ((JArray)obj))
{
if (property.GetType().Name == "JObject") GetObject(property, result, name, value);
if (property.GetType().Name == "JArray") GetObject(property, result, name, value);
if (property.GetType().Name == "JValue"
&& (value == null || (string)property == value))
{
if (getParent) result.Add((JArray)obj); else result.Add(property);
}
}
}
}

redux-persist, save only first 10 items using Transform

I'm trying to save only 2 items when persisting through redux-persist .
I'm perplexed why the following code won't work..
(it seems to save more than 2 items)
const myTransform = createTransform(
(inboundState, key) => {
let { openforum_threads } = inboundState
if (!openforum_threads) {
return inboundState
}
let { allIds } = openforum_threads
let STORE_NUM = 2
let storeIds = allIds.slice(0, STORE_NUM)
console.log('saving', storeIds)
let { byId } = openforum_threads
let storeById = {}
storeIds.map((id) => {
storeById[id] = byId[id]
})
openforum_threads = {
...openforum_threads,
allIds: storeIds,
byId: storeById
}
return { ...inboundState, openforum_threads}
},
(outboundState, key) => {
// convert mySet to an Array.
return outboundState
}
)

/var/www/vhosts/sahinucar.com.tr/httpdocs/wp-includes/wp-db.php on line 1890

My website is not working properly. I get this error:
/var/www/vhosts/xyz.com.tr/httpdocs/wp-includes/wp-db.php on line 1890
Following is the code on those lines. What is the problem in this code that it throws out an error?
// Return number of rows affected
$return_val = $this->rows_affected;
} else {
$num_rows = 0;
if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
**while ( $row = mysqli_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;**
}
} elseif ( is_resource( $this->result ) ) {
while ( $row = mysql_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
}
// Log number of rows the query returned
// and return number of rows selected
$this->num_rows = $num_rows;
$return_val = $num_rows;
}
return $return_val;
}
/**

Locking Telegram Custom Keyboard Buttons for Multiple Inputs

I am trying to lock the keys in the custom keyboard so the user can tap multiple buttons in the custom keyboard before sending the message. The default is you tap a custom keyboard button and message is sent, like with trivia bot. Any ideas on how to do this or if it is even possible?
If I understood right, what you want to do is multiselect (checkbox); there is no such function in telegram, but you can implement it a bit differently.
First, you send message with inline buttons and empty checkboxes with some text:
switch ($callback_query){
case 'choose':
$inline_keyboard = [
[
['text'=>'☐ 1', 'callback_data'=>"n1"],
['text'=>'☐ 2', 'callback_data'=>"n2"],
['text'=>'☐ 3', 'callback_data'=>"n3"]
],
[
['text'=>'☐ 4', 'callback_data'=>"n4"],
['text'=>'☐ 5', 'callback_data'=>"n5"]
],
[
['text'=>'Next', 'callback_data'=>"$someData"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
sendMessage($chat_id_callback, "Lorem ipsum dolor sit amet.", $replyMarkup);
break;
// When user is clicking on the buttons You process it with another case with all possible buttons in it and using telegram api to editMessageReplyMarkup
case "n1":
case "1":
case "n2":
case "2":
case "n3":
case "3":
case "n4":
case "4":
case "n5":
case "5":
$empty_checkbox = "☐";
$galochka = "✔";
if (substr($data,0,1)== "n"){
$is_checked = TRUE;
} else {
$is_checked = FALSE;
}
if ($is_checked){
$what_is_checked = substr($data, 1);;
} else {
$what_is_checked = $data;
}
// $output is variable, in wich telegram data is stored, which came through webhook
$text1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['text'];
$text2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['text'];
$text3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['text'];
$text4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['text'];
$text5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['text'];
$room_callback_data1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['callback_data'];
$room_callback_data2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['callback_data'];
$room_callback_data3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['callback_data'];
$room_callback_data4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['callback_data'];
$room_callback_data5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['callback_data'];
if ($what_is_checked == "1"){
if ($is_checked == TRUE) {
$text1 = $galochka . " 1";
$room_callback_data1 = "1";
} else {
$text1 = $empty_checkbox . " 1";
$room_callback_data1 = 'n2';
}
} elseif ($what_is_checked == "2"){
if ($is_checked == TRUE) {
$text2 = $galochka . " 2";
$room_callback_data2 = "2";
} else {
$text2 = $empty_checkbox . " 2";
$room_callback_data2 = 'n2';
}
} elseif ($what_is_checked == "3"){
if ($is_checked == TRUE) {
$text3 = $galochka . " 3";
$room_callback_data3 = "3";
} else {
$text3 = $empty_checkbox . " 3";
$room_callback_data3 = 'n3';
}
} elseif ($what_is_checked == "4"){
if ($is_checked == TRUE) {
$text4 = $galochka . " 4";
$room_callback_data4 = "4";
} else {
$text4 = $empty_checkbox . " 4";
$room_callback_data4 = 'n4';
}
} elseif ($what_is_checked == "5"){
if ($is_checked == TRUE){
$text5 = $galochka . " 5";
$room_callback_data5 = "5";
} else {
$text5 = $empty_checkbox . " 5";
$room_callback_data5 = 'n5';
}
}
$inline_keyboard = [
[
['text'=>$text1, 'callback_data'=>$room_callback_data1],
['text'=>$text2, 'callback_data'=>$room_callback_data2],
['text'=>$text3, 'callback_data'=>$room_callback_data3]
],
[
['text'=>$text4, 'callback_data'=>$room_callback_data4],
['text'=>$text5, 'callback_data'=>$room_callback_data5]
],
[
['text'=>'Next', 'callback_data'=>"remont"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
editMessageReplyMarkup($chat_id_callback, $message_id, $replyMarkup);
break;
}
In the second case, you are just checking which button was pressed and simply change empty box on check mark.
Also, you need to use answerCallbackQuery, to work properly:
function send_answerCallbackQuery($callback_query_id, $text ='', $alert = 0){
file_get_contents($GLOBALS['api']."/answerCallbackQuery?callback_query_id=".$callback_query_id . '&text=' . $text . '&show_alert=' . $alert);
}
if (isset($output['callback_query'])) {
send_answerCallbackQuery($output['callback_query']['id']);
}
It's a default behavior to preserve custom keyboard unless you set one_time_keyboard = True or return a ReplyKeyboardHide to a user.
See docs: https://core.telegram.org/bots/api#replykeyboardmarkup
Also you can send the same keyboard in a reply message every time you want to make sure the keyboard is displayed.

web grid server pagination trigger multiple controller call when changing page

When I server-filter on "au" my web grid and change page, multiple call to the controller are done :
the first with 0 filtering,
the second with "a" filtering,
the third with "au" filtering.
My table load huge data so the first call is longer than others.
I see the grid displaying firstly the third call result, then the second, and finally the first call (this order correspond to the response time of my controller due to filter parameter)
Why are all that controller call made ?
Can't just my controller be called once with my total filter "au" ?
What should I do ?
Here is my grid :
$("#" + gridId).kendoGrid({
selectable: "row",
pageable: true,
filterable:true,
scrollable : true,
//scrollable: {
// virtual: true //false // Bug : Génère un affichage multiple...
//},
navigatable: true,
groupable: true,
sortable: {
mode: "multiple", // enables multi-column sorting
allowUnsort: true
},
dataSource: {
type: "json",
serverPaging: true,
serverSorting: true,
serverFiltering: true,
serverGrouping:false, // Ne fonctionne pas...
pageSize: '#ViewBag.Pagination',
transport: {
read: {
url: Procvalue + "/LOV",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8"
},
parameterMap: function (options, type) {
// Mise à jour du format d'envoi des paramètres
// pour qu'ils puissent être correctement interprétés côté serveur.
// Construction du paramètre sort :
if (options.sort != null) {
var sort = options.sort;
var sort2 = "";
for (i = 0; i < sort.length; i++) {
sort2 = sort2 + sort[i].field + '-' + sort[i].dir + '~';
}
options.sort = sort2;
}
if (options.group != null) {
var group = options.group;
var group2 = "";
for (i = 0; i < group.length; i++) {
group2 = group2 + group[i].field + '-' + group[i].dir + '~';
}
options.group = group2;
}
if (options.filter != null) {
var filter = options.filter.filters;
var filter2 = "";
for (i = 0; i < filter.length; i++) {
// Vérification si type colonne == string.
// Parcours des colonnes pour trouver celle qui a le même nom de champ.
var type = "";
for (j = 0 ; j < colonnes.length ; j++) {
if (colonnes[j].champ == filter[i].field) {
type = colonnes[j].type;
break;
}
}
if (filter2.length == 0) {
if (type == "string") { // Avec '' autour de la valeur.
filter2 = filter2 + filter[i].field + '~' + filter[i].operator + "~'" + filter[i].value + "'";
} else { // Sans '' autour de la valeur.
filter2 = filter2 + filter[i].field + '~' + filter[i].operator + "~" + filter[i].value;
}
} else {
if (type == "string") { // Avec '' autour de la valeur.
filter2 = filter2 + '~' + options.filter.logic + '~' + filter[i].field + '~' + filter[i].operator + "~'" + filter[i].value + "'";
}else{
filter2 = filter2 + '~' + options.filter.logic + '~' + filter[i].field + '~' + filter[i].operator + "~" + filter[i].value;
}
}
}
options.filter = filter2;
}
var json = JSON.stringify(options);
return json;
}
},
schema: {
data: function (data) {
return eval(data.data.Data);
},
total: function (data) {
return eval(data.data.Total);
}
},
filter: {
logic: "or",
filters:filtre(valeur)
}
},
columns: getColonnes(colonnes)
});
Here is my controller :
[HttpPost]
public ActionResult LOV([DataSourceRequest] DataSourceRequest request)
{
return Json(CProduitsManager.GetProduits().ToDataSourceResult(request));
}
The 3 correspond to the initial load (no filtering) and the following ones as you type in the condition of filter, similar in kendoAutocomplete but in kendoAutocomplete there are a couple of options (time and min length) that control when to send the requests (I couldn't find anything similar in grid).
If your problem is loading a huge amount of data I do recommend limiting the size of the data transmitted using pageSize in the DataSource definition. But, obviously, this is not a solution if what takes long is executing the query.
In such scenarios it is recommended to create a typing delay and thus perform a request when the user has stopped typing (unless he is typing slower than regular typing).
To create a delay I can suggest you the following:
<script type="text/javascript">
var globalTimeout = null;
$('#searchInput').keyup(function () {
if (globalTimeout != null) clearTimeout(globalTimeout);
globalTimeout = setTimeout(SearchFunc, 500);
});
function SearchFunc(){
globalTimeout = null;
$('#yourGridName').data('kendoGrid').dataSource.filter({ field:"theField",operator:"startswith",value:$('#searchInput').val() })
}
</script>

Resources