dbr.editable linked report with javascript update

(9 posts) (2 voices)

Tags:

No tags yet.

  1. brycedcamp, Member

    I am calling a linked report with dbr.editable and updating a cell. The SQL update works great, however I want to update the css style for the cell that was just edited in the linked report also. Is this possible?

    This is the linked report entry and the stored procedure that does the update.

    select 'dbr.editable', 'deptprio22', 'sp_DBR_jobcosting_edit_deptprio22', 'inJobNum=jobnum', 'type=select', "select=select priorityid, prioritydesc from jobcosting.dbo.priorities";

    IF object_id('sp_DBR_jobcosting_edit_deptprio1','P') IS NOT NULL
    DROP PROCEDURE [sp_DBR_jobcosting_edit_deptprio1]
    GO
    CREATE PROCEDURE sp_DBR_jobcosting_edit_deptprio1
    @inJobNum int,
    @inValue int
    AS
    BEGIN

    UPDATE jobcosting.dbo.Master SET
    deptprio1=@inValue
    WHERE [Job #]=@inJobNum

    END
    GO

  2. myDBR Team, Key Master

    Hi,
    You can use callback option in dbr.editable to call a JavaScript function after the edit and perform the styling.

    select 'dbr.javascript', "function my_callback(value) {
    // value contains the ID when type=select
    // $(this).text() contains the user visible value
    // If the editable field is a formatted number, use cell_value_get(this) to get the numeric value
    }"; select 'dbr.editable', 'deptprio22', 'sp_DBR_jobcosting_edit_deptprio22', 'inJobNum=jobnum', 'type=select', "select=select priorityid, prioritydesc from jobcosting.dbo.priorities", "options={'callback':my_callback}";

    --
    myDBR Team

  3. brycedcamp, Member

    in the javascript call back function, can I make a call to a SQL dbo function to get the style from the DB?

  4. myDBR Team, Key Master

    How complex is the logic of the styling? What is the formatting you are trying to do?

    --
    myDBR Team

  5. brycedcamp, Member

    once the cell is updated, I want to update the CSS for that cell, say change the text color and the background color. I already do this when the report is loaded, but I need the cells to change as soon as the values are updated

  6. myDBR Team, Key Master

    You can return both the value and the style in JSON from the editing procedure and use the callback function to make use of these.

    The callback function:

    select 'dbr.javascript', "
    function my_callback(ret)
    {
    var o = jQuery.parseJSON(ret);
    cell_value_set( this, o.value );
    $(this).attr('style',o.style);
    }";

    And the return from the editing procedure:

    select concat('{"value":"',inValue, '","style":"',v_style,'"}');

    --
    myDBR Team

  7. brycedcamp, Member

    This is my new SP for the edit:

    IF object_id('sp_DBR_jobcosting_edit_deptprio1','P') IS NOT NULL
    DROP PROCEDURE [sp_DBR_jobcosting_edit_deptprio1]
    GO
    CREATE PROCEDURE sp_DBR_jobcosting_edit_deptprio1
    @inJobNum int,
    @inValue int
    AS
    BEGIN

    UPDATE jobcosting.dbo.Master SET
    deptprio1=@inValue
    WHERE [Job #]=@inJobNum

    select '{"value":"' + @inValue + '","style":"' + 'color:#FFFFFF;' + '"}';

    END
    GO

    I added an alert to the callback function, but I just get 'undefined'

    select 'dbr.javascript', "
    function my_callback(ret)
    {
    var o = jQuery.parseJSON(ret);
    cell_value_set( this, o.value );
    alert(o.value);
    $(this).attr('style',o.style);
    }";

  8. myDBR Team, Key Master

    In SQL Server you need to use cast/convert when concatenating strings and numbers.

    --
    myDBR Team

  9. brycedcamp, Member

    this works, thank you!


Reply

You must log in to post.