Regex searchCols problem
Regex searchCols problem
tchristfort
Posts: 22Questions: 7Answers: 0
I upgraded to Data Tables 1.12.1 and now the following search no longer produce any results:
"searchCols": [ null, null, { "search": "^40306", "regex" : true }],
Are there any changes in the syntax for this in 1.12.1?
If I remove the ^ and $ signs in above search pattern the rows are found correctly, so basically it seams as if it does not activate the regex feature.
Thomas
This question has an accepted answers - jump to answer
Answers
Your code works here with 1.12.1:
http://live.datatables.net/susevoke/1/edit
I added characters to the end of Edinburgh for Cedric Kelly and that row doesn't display.
Please update the test case or provide a link to your page or test case that replicates the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi Kevin,
I have cut down the file as much as possible and end up with a test page that demonstrate the problem: DataTablesTest.html
My problem seems related to the sever side feature. If I comment out the server side setting and run file on local data the seach works fine, but with server side data not.
You can access the page on this link: https://alfresco.ranchsystems.dk/weight/DataTablesTest.html
File code:
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
my copy paste of the code did not work. Is there a way to attach the file?
Thanks
Use Markdown. You will see this note below the
Post Comment
button:If you enable server side processing then the searching is to take place in the server script. First question is do you need server side processing enabled? Second is if you need server side processing are you using a Datatables supplied SSP script?
Your server script will need to process the column search parameters as described here. The server script will also need to support using regex search with your query.
Kevin
I need server side, and was not aware of a SSP script. This page is part of a larger system with many tables and pages with large tables. Server side is PHP and I pack return json manually, but please guide me to SSP documentation if this can help me.
What I want to achieve in the above code is just a cilent side filtering of data, this worked fine in DataTables 10.1 but apparently not in 12.1. If so I will have to rewrite and to a Server side search instead.
Thanks a lot for your help,
Thomas
Are you saying that with 1.10.1 you had server side processing enabled and the search worked?
Are you returning all rows or just the rows for the page? How are you handling paging of the data?
The server side processing protocol is documented here.
Kevin
I have programmed server side as per 10.1 documentation. My server side php for above page inserted below (split in two due to size).
Yes in 10.1 version the I had server side enabled and the search worked as expected.
```php
<?php > ``` ?>Editor::inst( $db, 'analysis' , 'number')
->fields(
Field::inst( 'analysis.number' )
->set( false ),
Field::inst( 'analysis.weighing_closed' ),
Field::inst( 'analysis.customer')
->validator( Validate::dbValues( ValidateOptions::inst()
->message( 'Kunden findes ikke' ),
'number',
'customer'
)),
Field::inst( 'analysis.item' )
->options( Options::inst()
->table( 'item' )
->value( 'number' )
->label( 'name' )
)
->validator( 'Validate::dbValues', array('message' => 'Varen findes ikke') )
->setFormatter( function($val, $data, $field) { if ($val==='') { return null; } else { return $val; };}),
Field::inst( 'analysis.date' )
->validator( Validate::dateFormat( 'd-m-Y' , ValidateOptions::inst()
->message( 'Ugyldig dato')))
->getFormatter( Format::dateSqlToFormat( 'd-m-Y' ) )
->setFormatter( Format::dateFormatToSql('d-m-Y' ) ),
Field::inst('analysis.time'),
Field::inst( 'analysis.moisture' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.density' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.protein' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.starch' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.gluten' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.zeleny' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.oil' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst('analysis.crop_template'),
Field::inst( 'analysis.sieve1' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return 0; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.sieve2' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return 0; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.sieve3' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return 0; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.sieve4' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return 0; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi')))
->validator( function ($val, $data, $field, $host ) {
if ((floatvalue($data['analysis']['sieve1'])+floatvalue($data['analysis']['sieve2'])+floatvalue($data['analysis']['sieve3'])+floatvalue($val))>100.01) {
return 'Summen af de 4 sold må ikke være over 100';
} else {
return true;
}
}),
Field::inst( 'analysis.fn' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.comment' )
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return $val; } }),
Field::inst( 'analysis.parti' ),
Field::inst( 'analysis.quantity' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return $val; } })
->getFormatter( function( $val, $data) { if($val === null) { return ''; } else { return $val; } })
->validator( Validate::numeric()),
Field::inst( 'analysis.ccc' ),
Field::inst( 'analysis.glyphosfat' ),
Field::inst( 'analysis.impurity' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst( 'analysis.germination' )
->setFormatter( function($val, $data, $field) { if($val === '') { return null; } else { return str_replace ( ',' , '.' , $val );}})
->getFormatter( function ( $val, $data) { if($val === null) { return ''; } else { return str_replace ( '.' , ',' , $val ); } })
->validator( Validate::numeric($decimal = ',', ValidateOptions::inst()
->message( 'Ugyldig værdi'))),
Field::inst('analysis.exported'),
Field::inst( 'customer.name'),
Field::inst( 'item.name')
)
->leftJoin('customer', 'customer.number', '=', 'analysis.customer')
->leftJoin('item', 'item.number', '=', 'analysis.item')
->on('preEdit', function ( $editor, $id, $data){
if (isset($_POST['nitID'])) {
if (!updateAnalysis($_POST['nitID'], $editor)) {
$reply = array ('error' => 'Kan ikke indlæse analysedata');
print json_encode($reply);
exit();
}
}
})
->on('preEdit', function ( $editor, $id, $values){
$editor
->field('analysis.exported')
->setValue(0);
})
->process( $_POST )
->json();
Hi @tchristfort,
Server-side processing in Editor's libraries don't support regular expressions for search I'm afraid. It never has, so I'm surprised that it used to work for you. Perhaps you had a modified version of the libraries that added that?
As you note, the search used for Editor's server-side processing is wildcard for prefix and postfix. This is the specific line that does that. If you wanted to, you could just remove the initial
%
there and it would give the effect you are looking for.Allan
Thanks for clarifying. I will rewrite for server side filtering