Help with Jagged Array needed, getting IQueryable results into an array - asp.net-mvc

Does anyone know how I can get my results currently in qry IQueryable object into a jagged array in the format:
series:
[{
name: '2',
data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
}, {
name: '3',
data: [1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0]
}]
My problem is the code I have at the moment wraps double quotes around the 12 element data part, i.e. it looks like this in the debugger on client side:
?result[0]
{...}
[0]: "2"
[1]: "[0,0,0,0,0,0,1,0,0,0,0,0]"
?result[1]
{...}
[0]: "3"
[1]: "[1,0,0,0,0,0,0,0,0,0,0,0]"
The problem is my array contains a single string element rather than an array of 12 numbers.
Here is my controller code that at the moment returns the 12 number part as one big string :
var qry = from i in _db.Complaints
where i.Site.SiteDescription.Contains(searchTextSite)
&& (i.Raised >= startDate && i.Raised <= endDate)
group i by i.ComplaintNatureTypeId.ToString()
into grp select new
{
Type = grp.Key,
Count = "[" + grp.Where(c => c.Raised.Month == 1).Count() + "," +
grp.Where(c => c.Raised.Month == 2).Count() + "," +
grp.Where(c => c.Raised.Month == 3).Count() + "," +
grp.Where(c => c.Raised.Month == 4).Count() + "," +
grp.Where(c => c.Raised.Month == 5).Count() + "," +
grp.Where(c => c.Raised.Month == 6).Count() + "," +
grp.Where(c => c.Raised.Month == 7).Count() + "," +
grp.Where(c => c.Raised.Month == 8).Count() + "," +
grp.Where(c => c.Raised.Month == 9).Count() + "," +
grp.Where(c => c.Raised.Month == 10).Count() + "," +
grp.Where(c => c.Raised.Month == 11).Count() + "," +
grp.Where(c => c.Raised.Month == 12).Count() + "]"
};
return Json(qry.ToArray(), JsonRequestBehavior.AllowGet);

You need to pass an object and Json will serialize it to a JSON string.
Count = new int[] {
grp.Where(c => c.Raised.Month == 1).Count(),
grp.Where(c => c.Raised.Month == 2).Count(),
grp.Where(c => c.Raised.Month == 3).Count(),
grp.Where(c => c.Raised.Month == 4).Count(),
grp.Where(c => c.Raised.Month == 5).Count(),
grp.Where(c => c.Raised.Month == 6).Count(),
grp.Where(c => c.Raised.Month == 7).Count(),
grp.Where(c => c.Raised.Month == 8).Count(),
grp.Where(c => c.Raised.Month == 9).Count(),
grp.Where(c => c.Raised.Month == 10).Count(),
grp.Where(c => c.Raised.Month == 11).Count(),
grp.Where(c => c.Raised.Month == 12).Count()
}
Or you could do something like:
Count = Enumerable.Range(1, 12).Select(x => grp.Where(c => c.Raised.Month == x).Count())

You are creating the count property as a string, should it not be an array:
Count = new [] {
grp.Where(c => c.Raised.Month == 1).Count(),
grp.Where(c => c.Raised.Month == 2).Count(),
...
grp.Where(c => c.Raised.Month == 12).Count()
}

Related

The Date stored in my database is like '2018-09-15 10:34:09',i want result of search in '15-09-2018' Format.I'm using Kartik datepicker to select date

I'm new in programming and I'm confused at one point. I'm using kartik datepicker to search date from table.In my table the date is stored in '2018-09-15 10:34:09' format. I'm using a stored procedure here and when I enter date (in format: 15-9-2018), I want to show some results.
My controller:
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Functions;
use backend\models\Meetmelicence;
use backend\models\MeetmelicenceSearch;
class MeetmelicenceController extends BackendController
{
public function actionIndex($redirect = '')
{
$searchModel = new MeetmelicenceSearch();
$model = new Meetmelicence();
if(isset($_GET['MeetmelicenceSearch']))
{
$searchModel->attributes = $_GET['MeetmelicenceSearch'];
}
if($redirect == 'success')
{
Yii::$app->session->setFlash('success', 'Import data processed
successfully.');
}
$transaction_id = $searchModel->transaction_id;
$transactionmodel = $this->findModeltransactionmodel($transaction_id);
return $this->render('index', [
'searchModel' => $searchModel,
'model' => $model,
'transactionmodel' =>$transactionmodel,
]);
}
protected function findModeltransactionmodel($id)
{
if (($model = Payment::findOne(['transaction_id' => $id])) !== null) {
return $model;
}
else {
return false;
}
}
}
Model:
<?php
namespace backend\models;
use Yii;
use backend\models\Backendcommon;
class Meetmelicence extends Backendcommon
{
public $transaction_id;
public $transaction_date;
public $new_expiry_date;
public static function tableName()
{
return 'meet_me_licence_master';
}
public function rules()
{
return [
[['created_on', 'updated_on','unit_id','unit_user_id','isEmail','recieve_calls','transaction_id','transaction_date','new_expiry_date','user_licence_status','remarks'], 'safe'],
[['licence_number','status'],'required'],//,'licence_password'
[['transaction_id'],'required'],
];
}
}
Search model:
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\StaffCategory;
use yii\data\SpDataProvider;
class MeetmelicenceSearch extends Meetmelicence
{
public function rules()
{
return [
[['new_expiry_date','transaction_id','new_expiry_date','transaction_date',], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search()
{
$arrParams = array();
$arrParams['v_private_key'] = \Yii::$app->params['private_db_key'];
$object_xml_array['transaction_date'] = $this->transaction_date;
$object_xml_array['new_expiry_date']=$this->new_expiry_date;
$xml = new \SimpleXMLElement('<CustomXML/>');
$this->function_model->_array_to_xml($object_xml_array, $xml, 0);
$object_xml_array = $xml->asXML();
$final_array_xml = urldecode($object_xml_array);
$arrParams['v_object_xml'] = $final_array_xml;
$dataProvider = new SpDataProvider([
'spName' => 'meet_me_licence_list',
'params' => $arrParams,
'sort' => [
'attributes' => [
'transaction_date' => [
'asc' => ['transaction_date' => SORT_ASC, 'transaction_date' => SORT_ASC],
'desc' => ['transaction_date' => SORT_DESC, 'transaction_date' => SORT_DESC],
'default' => SORT_ASC,
'label' => 'Transaction Date',
],
'new_expiry_date' => [
'asc' => ['new_expiry_date' => SORT_ASC, 'new_expiry_date' => SORT_ASC],
'desc' => ['new_expiry_date' => SORT_DESC, 'new_expiry_date' => SORT_DESC],
'default' => SORT_ASC,
'label' => 'New Transaction Expiry Date',
],
],
'pagination' => [
'pageSize' => 20,
],
]);
return $dataProvider;
}
}
My index file:
<?php
<div class="container">
<div class="panel panel-default">
<div class="panel-body" style="padding:0px">
<?php Pjax::begin(['timeout' => 500000,'enablePushState'=>false]); ?>
<?= GridView::widget([
'dataProvider' => $searchModel->search(),
'filterModel' => $searchModel,
// 'layout' => '{items}{pager}',
'layout' => '{items}{pager}{summary}',
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last'
],
'columns' =>
[
'attribute'=> 'transaction_date',
'filter'=>DatePicker::widget([
'attribute'=> 'transaction_date',
'model' => $searchModel,
'type' => DatePicker::TYPE_COMPONENT_APPEND,
// 'type' => DatePicker::TYPE_COMPONENT_PREPEND,
// 'type' => DatePicker::TYPE_INPUT,
// 'type' => DatePicker::TYPE_BUTTON,
'options' => ['id'=> 'searchmodel_transaction_date',],
// 'value'=>'23-Feb-1982',
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy',
'todayHighlight' => true,
]
]),
'contentOptions' => [ 'style' => 'width: 80%;' ],
],
[
'attribute'=> 'new_expiry_date',
'filter'=>DatePicker::widget([
'attribute'=> 'new_expiry_date',
'model' => $searchModel,
'type' => DatePicker::TYPE_COMPONENT_APPEND,
'options' => ['id'=> 'searchmodel_new_expiry_date',],
'value'=>'10/05/2022',
'pluginOptions' => [
'autoclose' => false,
'format' => 'dd-M-yyyy',
'todayHighlight' => true,
]
]),
'contentOptions' => [ 'style' => 'width: 80%;' ],
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
</div>
</div>
My stored procedure:
DELIMITER $$
USE `fermax_crm_local_4_31`$$
DROP PROCEDURE IF EXISTS `meet_me_licence_list`$$
CREATE DEFINER=`dbfermaxcrm`#`%` PROCEDURE `meet_me_licence_list`(
IN v_private_key VARCHAR(100),
IN v_licence_number VARCHAR(255),
IN v_object_xml TEXT,
IN v_Sort TEXT,
IN v_limit INT,
IN v_pageIndex INT)
BEGIN
/*
*/
DECLARE v_Select TEXT DEFAULT "";
DECLARE v_Where TEXT DEFAULT " WHERE 1";
DECLARE v_From TEXT DEFAULT "";
DECLARE v_OrderBy TEXT DEFAULT "";
DECLARE v_QueryLimit TEXT DEFAULT "";
DECLARE v_group_by TEXT DEFAULT "";
DECLARE v_having TEXT DEFAULT "";
DECLARE
v_transaction_date,v_new_expiry_date DEFAULT "";
DECLARE v_transaction_id INT DEFAULT 0;
SET SESSION group_concat_max_len = 1000000000;
SET v_transaction_date = EXTRACTVALUE(v_object_xml, '//transaction_date[$#1]');
SET v_new_expiry_date = EXTRACTVALUE(v_object_xml, '//new_expiry_date[$#1]');
SET v_transaction_id = EXTRACTVALUE(v_object_xml, '//v_transaction_id[$#1]');
CALL add_query_log(0,0,'meet_me_licence_list',CONCAT("CALL meet_me_licence_list('"
,IFNULL(v_private_key,''),"','"
,IFNULL(v_licence_number,''),"','"
,IFNULL(v_object_xml,''),"','"
,IFNULL(v_Sort,''),"','"
,IFNULL(v_limit,''),"','"
,IFNULL(v_pageIndex,''),"',"
,");"
));
SET v_Select = CONCAT(" SELECT
mmlm.meet_me_licence_id
,mmlm.most_recent_audit_log
,get_date_string(mmlt.transaction_date,1,1, ' %d %b %Y %h:%i %p ') AS transaction_date
,get_date_string(mmlt.new_expiry_date ,1,1, ' %d %b %Y %h:%i %p ') AS new_expiry_date
");
SET v_From = CONCAT(" FROM meet_me_licence_master AS mmlm
LEFT JOIN meet_me_licence_transaction mmlt
ON mmlm.meet_me_licence_id= mmlt.meet_me_licence_id
LEFT JOIN unit un
ON CAST(un.unit_id AS CHAR) = CAST(mmll.unit_id AS CHAR)
");
SET v_Where = CONCAT(v_Where," AND mmlm.status != 3 ");
IF (IFNULL(v_transaction_date,'') != '') THEN
SET v_Where = CONCAT(v_Where," AND mmlt.transaction_date ='", v_transaction_date,"' ");
END IF;
IF (IFNULL(v_new_expiry_date,'') != '') THEN
SET v_Where = CONCAT(v_Where," AND mmlt.new_expiry_date = '",v_new_expiry_date,"' ");
END IF;
-- IF (v_sort_order != '') THEN
-- SET v_Where = CONCAT(v_Where," AND lower(c.sort_order) LIKE '%",v_sort_order,"%' ");
-- END IF;
SET v_group_by = CONCAT(" GROUP BY mmlm.meet_me_licence_id ");
SET #rec_Query = CONCAT(v_Select
,v_From
,v_Where
,v_group_by
,v_having
);
-- SET #cnt_Query = CONCAT("Select Count(*) INTO #o_RecCount FROM (",#rec_Query,") AS tmp");
SET #cnt_Query = CONCAT("Select Count(*) as o_RecCount FROM (",#rec_Query,") AS tmp");
-- IF(v_Sort != "") THEN
/*SET v_OrderBy = CONCAT("
ORDER BY CASE WHEN IFNULL(mmlm.updated_on,'0000-00-00 00:00:00') != '0000-00-00 00:00:00' then mmlm.updated_on
ELSE mmlm.`created_on` END DESC
");*/
-- END IF;
IF(v_Sort != "") THEN
SET v_OrderBy = CONCAT(" ORDER BY ",v_Sort);
ELSE
SET v_OrderBy = CONCAT("
ORDER BY CASE WHEN IFNULL(mmlm.updated_on,'0000-00-00 00:00:00') != '0000-00-00 00:00:00' then mmlm.updated_on
ELSE mmlm.`created_on` END DESC
");
END IF;
IF (v_PageIndex) > 0 THEN
SET v_QueryLimit = CONCAT(" LIMIT ", v_limit, "," , v_pageIndex);
END IF;
SET #vv_Query= CONCAT(v_Select
,v_From
,v_Where
,v_group_by
,v_OrderBy
,v_QueryLimit);
SELECT #vv_Query;
PREPARE s1 FROM #vv_Query;
EXECUTE s1;
PREPARE c2 FROM #cnt_Query;
EXECUTE c2;
-- select #cnt_Query;
END$$
DELIMITER ;

Telerik Client Template Conditions

I am using Telerik MVC Grid control to show a data grid. The detail of my grid is calling the following Client Detail template:
<script id="client-template" type="text/x-kendo-template"> <%: Html.Kendo().Grid<ASML_Scheduler.ScheduleService.AgentViewData>()
.Name("grid_#=WorkgroupName#")
.DataSource(dataSource =>
dataSource.Ajax().Read(read => read.Action("Agents_Read", "Home", new {workgroupname= "#=WorkgroupName#", name = ViewData["LoggedInUser"] }))
)
.Columns(columns =>
{
columns.Bound(product => product.AgentName).ClientTemplate("<strong>\\#:AgentName\\#</strong>");
//columns.Bound(product => product.IsLoggedOn);
//columns.Bound(product => product.IsLoggedOn).ClientTemplate("<div class='mystyle'>\\#:IsLoggedOn\\#</div>");
columns.Bound(product => product.IsLoggedOn).ClientTemplate(
"# if (IsLoggedOn != false) { #" +
"<div class='mystyle'>\\#:IsLoggedOn\\#</div>" +
"# } else { #" +
"<div>\\#:IsLoggedOn\\#</div>" +
"# } #"
);
columns.Bound(product => product.IsScheduled);
})
.ToClientTemplate()
%>
</script>
The problem I have is with the IsLoggedOn client template as it does not recognise the IsLoggedOn != false.
Can anyone see what I havedone wrong here.
personally with this sort of thing I prefer doing this.
change this:
columns.Bound(product => product.IsLoggedOn).ClientTemplate(
"# if (IsLoggedOn != false) { #" +
"<div class='mystyle'>\\#:IsLoggedOn\\#</div>" +
"# } else { #" +
"<div>\\#:IsLoggedOn\\#</div>" +
"# } #"
);
to
columns.Bound(product => product.IsLoggedOn)
.ClientTemplate("#=StyleLogin(data.IsLoggedOn)#");
then create a javascript function
function StyleLogin(IsLoggedOn)
{
var value = '';
if (IsLoggedOn != false) {
value = '<div class="mystyle">' + IsLoggedOn + '</div>';
} else {
value = '<div>' + IsLoggedOn + '</div>';
}
return value;
}
This way you can easily debug the code and also reuse the function elsewhere if needed.

NHibernate QueryOver with WhereRestriction as OR

I have this query but I can't seem to find how I set my WhereRestrictionOn as an OR. Now they function as AND but I want one OR the other.
var privateInfo = Session.QueryOver<ConContact>()
.JoinAlias(c => c.PrivateInfos, () => pi)
.WhereRestrictionOn(c => c.FirstName).IsLike(_selectedFirstLetter + "%")
.WhereRestrictionOn(c => c.LastName).IsLike(_selectedFirstLetter + "%") // todo: change to firstname OR lastname
.Where(c => c.Status == ContactStatus.Approved)
.Select(
Projections.Property("pi.Id").WithAlias(() => sri.Id),
Projections.Property("FirstName").WithAlias(() => sri.Name), //todo: get fullname here => Add concontact object in privateinfo
Projections.Property("pi.Address").WithAlias(() => sri.Address),
Projections.Constant("Contact").WithAlias(() => sri.Type)
)
.TransformUsing(Transformers.AliasToBean<SearchResultInfo>())
.List<SearchResultInfo>()
.ToList();
Any help is much appreciated thx!
SOLUTION:
var privateInfo = Session.QueryOver<ConContact>()
.JoinAlias(c => c.PrivateInfos, () => pi)
.Where(
Restrictions.Disjunction()
.Add(Restrictions.Like("FirstName", _selectedFirstLetter + "%"))
.Add(Restrictions.Like("LastName", _selectedFirstLetter + "%"))
)
.Where(c => c.Status == ContactStatus.Approved)
.Select(
Projections.Property("pi.Id").WithAlias(() => sri.Id),
Projections.Property("FirstName").WithAlias(() => sri.Name), //todo: get fullname here => Add concontact object in privateinfo
Projections.Property("pi.Address").WithAlias(() => sri.Address),
Projections.Constant(NewObjectType.Contact).WithAlias(() => sri.Type)
)
.TransformUsing(Transformers.AliasToBean<SearchResultInfo>())
.List<SearchResultInfo>()
.ToList();
The top level .Where() family (including WhereRestrictionOn) is always joined with AND. So we have to explicitly use something like:
Restrictions.Or(restriction1, restriction1)
Restrictions.Disjunction().Add(restriction1).Add(restriction2).Add(...
So, this could be our case:
.Where(
Restrictions.Disjunction()
.Add(Restrictions.On<ConContact>(c => c.FirstName)
.IsLike(_selectedFirstLetter, MatchMode.Start))
.Add(Restrictions.On<ConContact>(c => c.LastName)
.IsLike(_selectedFirstLetter, MatchMode.Start))
// more OR ...
//.Add(Restrictions.On<ConContact>(c => c.MiddleName)
// .IsLike(_selectedFirstLetter, MatchMode.Start))
)
As discussed here: 16.2. Simple Expressions, for simple stuff we can even use || (cited small example):
.Where(p => p.Name == "test name" && (p.Age > 21 || p.HasCar))

Date Formatting not working - Telerik grid details

I am hoping this is easy. I googled and looked through the forums and cannot find a solid answer. One answer was to add the calendar js file but that did not seem to work.
Look at the highlighted code below. The first 2, with formatting defined, are blank and should not be. The next 2 have real long date formats when all I need is “MM/dd/yyyy”. Yikes!
<%= Html.Telerik().Grid<ViewModelProcurementAction>(Model.ProcurementActions) //
.Name("ProcurementActionGrid")
.DetailView(details => details.ClientTemplate(
Html.Telerik()
.TabStrip()
.Name("TabStrip_<#= Id #>")
.SelectedIndex(0)
.Items(items =>
{
items.Add().Text("Additional Info").Content(
"<table>" +
"<tr>" +
"<td style='vertical-align: top'>" +
"<b>Summary Description:</b><br/><#= SummaryDescription #>" +
"</td>" +
"<td style='vertical-align: top'>" +
//"<ul>" +
"<b>Modification Number:</b> <#= ModificationNumber #><br/>" +
"<b>Funding Type:</b> <#= FundingTypeName #><br/>" +
"<b>Department Name:</b> <#= DepartmentName #><br/>" +
"<b>Solicitation Type:</b> <#= SolicitationTypeName #><br/>" +
"<b>Date Entered:</b> <#= $.telerik.formatString('{0:d}', DateEntered) #><br/>" +
//"</ul>" +
"</td>" +
"<td style='vertical-align: top'>" +
"<b>FY12:</b> <#= $.telerik.formatString('{0:c0}', FyByKey[\"FY12\"]==null ? 0 : FyByKey[\"FY12\"]) #><br/>" +
"<b>FY13: </b><#= $.telerik.formatString('{0:c0}', FyByKey[\"FY13\"]==null ? 0 : FyByKey[\"FY13\"]) #><br/>" +
"<b>FY14: </b><#= $.telerik.formatString('{0:c0}', FyByKey[\"FY14\"]==null ? 0 : FyByKey[\"FY14\"]) #><br/>" +
"<b>FY15: </b><#= $.telerik.formatString('{0:c0}', FyByKey[\"FY15\"]==null ? 0 : FyByKey[\"FY15\"]) #><br/>" +
"<b>FY16: </b><#= $.telerik.formatString('{0:c0}', FyByKey[\"FY16\"]==null ? 0 : FyByKey[\"FY16\"]) #><br/>" +
"<b>FY17: </b><#= $.telerik.formatString('{0:c0}', FyByKey[\"FY17\"]==null ? 0 : FyByKey[\"FY17\"]) #><br/>" +
"<b>Out Year Funding: </b><#= $.telerik.formatString('{0:c0}', OutYearFunding==null ? 0 : OutYearFunding ) #><br/>" +
"</td>" +
"<td style='vertical-align: top'>" +
"<b>DBE %: </b><#= $.telerik.formatString('{0:0}', DBE==null ? 0 : DBE) #><br/>" +
"<b>Amount Exceeds: </b><#= AmountExceeds #><br/>" +
//--------------------------------------------------------------------------------
"<b>Cost/Price Analysis Date: </b><#= $.telerik.formatString('{0:MM/dd/yyyy}', CostPriceAnalysisDate==null ? '' : CostPriceAnalysisDate) #><br/>" +
"<b>OIG Review Completion Date: </b><#= $.telerik.formatString('{0:shortDate}', OIGReviewCompletionDate==null ? '' : OIGReviewCompletionDate) #><br/>" +
"<b>Required Procurement Initiation Date: </b><#= RequiredProcurementInitiationDate #><br/>" +
"<b>Required Date of Award: </b><#= RequiredDateOfAward #><br/>" +
//--------------------------------------------------------------------------------
"<b>Number of Option Years: </b><#= NumberOfOptionYears #><br/>" +
"<b>Budget Approval: </b><#= BudgetApproval #><br/>" +
"<b>Point of Contact: </b><#= PointOfContact #><br/>" +
"</td>" +
"<td style='vertical-align: top'>" +
"<b>PRMT Group: </b><#= PRMTGroupName #><br/>" +
"<b>Planned CA Responsible: </b><#= PlannedCAResponsibleFullName #><br/>" +
"<b>Value of Option Years: </b><#= $.telerik.formatString('{0:0}', ValueOfOptionYears==null ? 0 : ValueOfOptionYears) #><br/>" +
"<b>Award Amount: </b><#= $.telerik.formatString('{0:0}', AwardAmount==null ? 0 : AwardAmount) #><br/>" +
"<b>Awarded Vendor: </b><#= AwardedVendor #><br/>" +
"<b>Multiple Year Funding: </b><#= MultipleYearFunding #><br/>" +
"<b>Period of Performance: </b><#= $.telerik.formatString('{0}{1}{2}', PeriodOfPerformanceStartDate==null ? '' : PeriodOfPerformanceStartDate, PeriodOfPerformanceEndDate==null ? '' : ' - ', PeriodOfPerformanceEndDate==null ? '' : PeriodOfPerformanceEndDate) #><br/>" +
"<b>Comments: </b><#= Comments #><br/>" +
"</td>" +
"</tr>" +
"</table>"
);
items.Add().Text("Purchase of Materials").Content(
"<br/><input type='checkbox' disabled='disabled' name='AwaitingProcurementPackEnabled' <#= AwaitingProcurementPackEnabled ? checked='checked' : '' #> /> <b>Awaiting Procurement pack from Point of Contact</b><br/>" +
Html.Telerik()
.Grid<ViewModelProcurementActivity>()
.Name("ActionGrid_<#= Id #>")
.Footer(false)
.Columns(c =>
{
c.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
}).Title("Actions").Width(120);
c.Bound(e => e.ActivityId).Visible(false);
c.Bound(e => e.Activity);
c.Bound(e => e.OriginalPlannedDate);
c.Bound(e => e.CurrentPlannedDate);
c.Bound(e => e.ActualDate);
c.Bound(e => e.ReasonForDateChange);
})
.DataBinding(dataBinding =>
dataBinding.Ajax()
.Select("AjaxGetActionDatesFor", "ProcurementActions", new { procurementActionId = "<#= Id #>" })
.Update("AjaxUpdateActionDatesFor", "ProcurementActions")
.Enabled(true)
)
.DataKeys(keys => keys.Add(c => c.ActivityId))
.Editable(editing => editing.Mode(GridEditMode.InLine)
)
.Selectable()
.ToHtmlString()
);
})
.ToHtmlString()
))
.Columns(c =>
{
c.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
commands.Delete().ButtonType(GridButtonType.ImageAndText);
commands.Custom("showHistory")
.ButtonType(GridButtonType.ImageAndText)
.Text("History")
.Action("Show", "ProcurementActions")
.DataRouteValues(route => { route.Add(o => o.Id).RouteKey("id"); });
}).Title("Actions").Width(100);
c.Bound(e => e.Id).Visible(false);
c.Bound(e => e.ActionId).Visible(false);
c.Bound(e => e.ContractNumber).HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.ContractManager).Width(120).HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.ActualCAResponsible).Width(150).HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.TitleOfRequirement).HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.CipOrName).Title("Project Id").HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.RecordTypeName).Title("Record Type").HtmlAttributes(new {style = "vertical-align: top"});
c.Bound(e => e.FullContractType).Title("Contract Type").HtmlAttributes(new { style = "vertical-align: top" });
c.Bound(e => e.ProcurementActionYearDisplayName).Title("Plan FY").HtmlAttributes(new { style = "vertical-align: top" });
})
.DataKeys(keys => keys.Add(o => o.Id))
.DataBinding(dataBinding =>
dataBinding.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxGetAll", "ProcurementActions") //, new { procurementActionId = "<#= CurrentAction #>" })
.Update("AjaxUpdate", "ProcurementActions")
.Delete("AjaxDelete", "ProcurementActions")
.Enabled(true)
)
.Editable(editing =>
editing.Mode(GridEditMode.PopUp)
.TemplateName("EditProcurementAction")
//? .AdditionalViewData(new { ListAllProcurementActionDateTypes = Model.AllProcurementActionDateTypes })
//? .AdditionalViewData(Model.AllUsers)
//? .AdditionalViewData(Model.ContractTypes)
//? .AdditionalViewData(Model.FundingTypes)
)
.Pageable(paging => paging.PageSize(15))
.Scrollable(scrolling => scrolling.Height(500))
.Filterable()
.Sortable()
%>
At the end of my file I changed this:
<%= Html.Telerik().ScriptRegistrar() %>
To this:
<%= Html.Telerik()
.ScriptRegistrar()
.DefaultGroup(group => group.Add("telerik.common.js")
.Add("telerik.calendar.js")
.Add("telerik.datepicker.js")
.Add("telerik.textbox.js"))
%>
Still nothing.
I am trying to deliver this today (for the final time) and am getting dinged for formatting.
Any thoughts?
-kb
So I finally tracked down how to do this correctly in the ClientTemplate:
"<b>Cost/Price Analysis Date: </b><#= $.telerik.formatString('{0:MM/dd/yyyy}', CostPriceAnalysisDate==null ? \"\" : CostPriceAnalysisDate) #><br/>" +
"<b>OIG Review Completion Date: </b><#= $.telerik.formatString('{0:MM/dd/yyyy}', OIGReviewCompletionDate==null ? \"\" : OIGReviewCompletionDate) #><br/>" +
"<b>Required Procurement Initiation Date: </b><#= $.telerik.formatString('{0:MM/dd/yyyy}', RequiredProcurementInitiationDate==null ? \"\" : RequiredProcurementInitiationDate) #><br/>" +
"<b>Required Date of Award: </b><#= $.telerik.formatString('{0:MM/dd/yyyy}', RequiredDateOfAward==null ? \"\" : RequiredDateOfAward) #><br/>" +
You need to make a call into $.telerik.formatString(...)

How to have the same behavior than 'params' function?

Controller functions receivent parameters like
{"v1" => { "v2" => "1", "v3" => "" }, "v4" => "true"}
The params function allows to use
x = params[:v1], equivalent to x = params["v1"]
if params[:v4], equivalent to ["true", "1"].include?(params["v4"])
if (params[:v1][:v2] == 1), equivalent to params["v1"]["v2"] == "1"
Is there any method to have the behavior than params function, but with other datas ?
I want to be able to write something like that...
my_params = {"v1" => { "v2" => "1", "v3" => "" }, "v4" => "true"}
x = my_params[:v1]
if my_params[:v4]
if (my_params[:v1][:v2] == 1)
Or with a function some_function
x = some_function(my_params)[:v1]
if some_function(my_params)[:v4]
if some_function(my_params)[:v1][:v2] == 1)
I'm in Rails 2.
You want a hash with indifferent access:
h = { a: { b: 1, 'c' => 2 } }
=> {:a=>{:b=>1, "c"=>2}}
h[:a][:c]
=> nil
h2 = h.with_indifferent_access
=> {"a"=>{"b"=>1, "c"=>2}}
h2['a'][:c]
=> 2
h2[:a][:c]
=> 2

Resources